Monday, April 23, 2012

xcode objective c - when I call 2 methods - only the last called method runs and first one is skipped

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{

[self NextHeading]; // this plays an mp3 file

[self NextHeadingMeaning]; // this plays an Mp3 file

}


Only [self NextHeadingMeaning] method is called and NextHeading method is missed each time



-(IBAction) NextHeading{ 
[audio stop];

NSString *Filename = [[NSString alloc]initWithFormat:@"CH%@S%@",Heading,Meaning];
Filepath = [[NSBundle mainBundle]pathForResource:Filename ofType:@"mp3"];

audio = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:Filepath] error:NULL];

audio.delegate = self;
[audio play];
[Filename autorelease];
}

-(IBAction) NextHeadingMeaning {
[audio stop];

NSString *Filename = [[NSString alloc] initWithFormat:@"CH%@S%@",bold**Chapter**bold, Meaning];
Filepath = [[NSBundle mainBundle]pathForResource:Filename ofType:@"mp3"];

audio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:Filepath] error:NULL];

audio.delegate = self;
[audio play];
[Filename autorelease];
}


Why is this happening and how can I resolve it ?



Please advice, thanks in advance.





No comments:

Post a Comment