【问题标题】:iPhone SDK AVAudioPlayer - stop and then fail to startiPhone SDK AVAudioPlayer - 停止然后无法启动
【发布时间】:2011-01-25 08:46:41
【问题描述】:
- (IBAction)triggerSound {
    if (player == nil) {
        NSError *error;
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    } else if ([player isPlaying]) {
        [player stop];
        player.currentTime = 0;
    }

    if (![player play]) {
        NSLog(@"fail");
    }
}

其中 player 是 AVAudioPlayer,此操作与 UIButton 链接。声音可以播放,声音结束后可以再次播放,但是在播放过程中再次按下按钮时,记录“失败”消息,无法播放声音,没有任何异常。

我在 iOS 4.2.1 上使用 iPad。

【问题讨论】:

    标签: ios4 avaudioplayer


    【解决方案1】:

    我注意到在调用 stop 后音频流无法播放(根据参考,它取消了 prepareToPlay 和 play 所做的操作)。 将 currentTime 设置为 player.duration(end of the stream) 而不是调用 stop。

    【讨论】:

      猜你喜欢
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多