开发者

Audio Player loop running multiple times

I am developing a ebook reader. There are some audio files which needs to be played upon clicking on a icon. The audio just plays fine for the first time. But when I press the home button of the app and return into the audio player, the audio is being played twice. The number keeps increasing by 1 every time I press the home button and 开发者_StackOverflow社区come back to the audio player. Using debugger I found that this loop is running multiple times. Can anyone explain why is it behaving like that?

-(void)StartPlayingFileWithNotification:(NSNotification *)notifcation{
// Load the array with the sample file
NSString *f = [[notifcation userInfo] valueForKey:@"audiopath"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: f];
if(fileURL == nil){
    GLogError(@"%@",@"File Not Found");
    return;
}else {
    GLogInfo(@"%@",@"Got audio file");
}
if (self.player != nil) {
    if (self.player.playing) {
        [self.player stop];
    }
    [player release];
    player = nil;
}

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];  
if (self.player)
{
    fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[player.url relativePath] lastPathComponent], player.numberOfChannels, nil];
    NSLog(@"The audio file is %@",fileName.text);
    NSLog(@"The file URL is %@",[fileURL description]);

    [self updateViewForPlayerInfo:player];
    player.numberOfLoops = 0;
    player.delegate = self;
    [player play];
    [self updateViewForPlayerState:player];
}
[fileURL release];

}


Check your @synthesize, member var and @property declarations. Don't you have a typing mistake ? Use self.player everywhere, or just player, but try avoiding mixing both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜