【问题标题】:Audio Player loop running multiple times音频播放器循环多次运行
【发布时间】:2011-01-24 06:38:12
【问题描述】:

我正在开发电子书阅读器。有一些音频文件需要在单击图标时播放。音频第一次播放良好。但是当我按下应用程序的主页按钮并返回音频播放器时,音频正在播放两次。每次按下主页按钮并返回音频播放器时,数字都会增加 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];
    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];

}

【问题讨论】:

    标签: iphone objective-c ios ipad avaudioplayer


    【解决方案1】:

    检查您的 @synthesize、成员 var 和 @property 声明。你没有打字错误吗?在任何地方都使用self.player,或者只使用player,但尽量避免将两者混用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      相关资源
      最近更新 更多