开发者

Audio playing twice upon pressing the home button

HI guys, 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 come back to the audio player.... Please help me with ur inputs.... by debugging i found that this loop is running multiple times... Can anyone tell me the reason for it??

-(void)StartPlayingFileWithNotification:(NSNotificatio开发者_Go百科n *)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];
    [self updateViewForPlayerInfo:player];
    player.numberOfLoops = 0;
    player.delegate = self;
    [player play];
    [self updateViewForPlayerState:player];
}
[fileURL release];

}


Sounds like you are creating new views (or other objects) containing your audio player without checking to see if the previous one is still around and running. You could either check on activate before creating another one, or clean up the old one when the app resigns active.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜