gpt4 book ai didi

iphone - AVPlayer 在 iPhone 上结束中断时不会恢复播放,但在 iPad 上会这样做

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:29 25 4
gpt4 key购买 nike

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

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

  1. 在 iPad 上:如果我强制中断(Facetime 通话),beginInterruption 将按预期调用,播放停止。如果中断停止,endInterruption 将按预期调用,播放将按预期恢复。
  2. 在 iPhone 上:按下播放和暂停按钮,触发 pauseplaybeginInterruption 完全相同而 endInterruption 会。播放行为符合预期。
  3. 在 iPhone 上:强制中断(通过调用电话),按预期调用 endInterruption 并按预期暂停播放。然而,当中断完成时,beginInterruption 被调用,play 被调用,它实际上到达并执行了 [self.player播放],但播放不会恢复!我什么也没听到。

上面的情况3非常奇怪,所以我想知道我是否忽略了什么。有什么想法吗?

播放代码

- (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];

关于iphone - AVPlayer 在 iPhone 上结束中断时不会恢复播放,但在 iPad 上会这样做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12461691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com