AVPlayer不会在iPhone上的结束中断时继续播放,但在iPad上也是如此

我正在为iPhone和iPad编写一个广播应用程序,并在处理暂停和播放audio时遇到一些奇怪的行为。 我使用AVAudioSessionDelegate方法beginInterruptionendInterruption来分别pauseplay AVPlayer。 以下是相关的play代码。

现在,以下情况似乎一致发生:

  1. 在iPad上:如果我强制中断(Facetime调用), beginInterruption预期调用beginInterruption并停止播放。 如果中断停止, endInterruption按预期endInterruption被调用,并且播放按照预期恢复。
  2. 在iPhone上:按下播放和暂停button,触发pauseplaybeginInterruptionendInterruption 。 播放行为如预期。
  3. 在iPhone上:强制中断(通过拨打电话),按预期调用endInterruption按照预期暂停播放。 但是,当中断完成时, beginInterruption被调用为预期的, play被调用为预期, 它实际上到达并执行[self.player play] ,但播放不会恢复! 我什么也没听到。

以上情况3是非常奇怪的,所以我想知道我是否可能忽略了一些东西。 有任何想法吗?

Play代码

 - (void)play { NSError* error = nil; AVKeyValueStatus keyStatus = [currentAsset statusOfValueForKey:@"tracks" error:&error]; if(error){ DLog(@"Error %@", [error localizedDescription]); } else { DLog(@"Current Key Status: %i", keyStatus); if(keyStatus == AVKeyValueStatusLoaded){ DLog(@"Continue playing source: %@", self.source); [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; if (error) { DLog(@"Error during play while setting AVAudioSessionCategory: %@", [error localizedDescription]); } [[AVAudioSession sharedInstance] setActive:YES error:&error]; if (error) { DLog(@"Error during play while setting AVAudioSessionCategory: %@", [error localizedDescription]); } [[AVAudioSession sharedInstance] setDelegate:self]; if(backgroundTaskID != UIBackgroundTaskInvalid){ [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskID]; } backgroundTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL]; [self.player play]; [self setStatus:kNPOMediaPlayerStatusPlaying]; } else { DLog(@"PlaySource: %@", self.source); [self playSource:self.source]; } }} 

我遇到过同样的问题。 执行远程控制事件处理后问题消失。 我调用了[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 当开始播放时。

事实certificate,这是iOS中的一个已知错误,需要在applicationDidBecomeActive中仔细处理beginInterruption。 可悲的是,我找不到另一种解决scheme。