2011-01-20 112 views
0

嗨,我正在开发电子书阅读器。有些音频文件需要点击图标才能播放。该音频第一次播放良好..但是,当我按下应用程序的主页按钮,并返回到音频播放器,音频播放两次......每次我按下家中的数字不断增加1按钮并回到音频播放器....请帮助我与你的投入....通过调试我发现这个循环运行多次...任何人都可以告诉我它的原因?按下主页按钮后播放两次音频

-(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]; 
    [self updateViewForPlayerInfo:player]; 
    player.numberOfLoops = 0; 
    player.delegate = self; 
    [player play]; 
    [self updateViewForPlayerState:player]; 
} 
[fileURL release]; 

}

回答

0

听起来像你不检查,看是否与前一个仍然存在并运行创建包含音频播放器的新观点(或其他物体)。您可以在创建另一个之前检查激活,或者在应用程序退出活动时清理旧的。

+0

嗨hotpaw2 ....非常感谢你的答案....你可以请解释我多一点如何做到这一点....我使用单身对象来分配音频文件,但仍然我找不到解决方案.. – 2011-01-24 03:30:15

相关问题