即使类别为AVAudioSessionCategoryPlayback,AVAudioPlayer也会停止在屏幕锁定上播放 [英] AVAudioPlayer stops playing on screen lock even though the category is AVAudioSessionCategoryPlayback

查看:174
本文介绍了即使类别为AVAudioSessionCategoryPlayback,AVAudioPlayer也会停止在屏幕锁定上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用AVAudioPlayer播放音频播放列表。我没有更改iOS4.3和iOS5之间的代码。但是,iOS5上的音频会暂停屏幕锁定,即使我已将类别设置为AVAudioSessionCategoryPlayback。

My app uses AVAudioPlayer to play through audio playlists. I haven't changed the code between iOS4.3 and iOS5. However, the audio on iOS5 pauses on a screen lock even though I've set the category to be AVAudioSessionCategoryPlayback.

我已经在iOS4.3和iOS5上测试了代码设备和这个问题发生在iOS5设备上。

I've tested the code on iOS4.3 and iOS5 devices and this problem occurs on the iOS5 device.

还有其他人遇到过这个问题吗?我不知所措,因为我甚至不知道从哪里开始调试这个问题。我的调试开始并以检查AVAudioSessionCategory设置结束。

Has anyone else faced this problem? I'm at a loss since I don't even know where to start debugging this issue. My debugging started and ended with checking the AVAudioSessionCategory setting.

我正在执行的代码是:

[[AVAudioSession sharedInstance] setDelegate: self];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];

编辑:

我已经实施并处理 audioPlayerBeginInterruption

编辑#2:解决!感谢 Rhythmic Fistman's Answer

这是发生了什么以及发生了什么我做到了。即使屏幕被锁定,iOS5也会立即将应用程序推送到后台。这意味着您需要在应用程序中启用背景音频,并使处理该音频的任何视图/视图控制器成为第一响应者。

Here's what was happening and what I did. iOS5 changes now push your app to the background even when the screen gets locked. This means that you need to enable background audio in your app, and make whatever view/viewcontroller handling that audio to be the first responder.

步骤1:
在您的应用中启用背景音频

第2步:
启用远程事件并成为负责处理音频播放列表的viewcontroller / view的第一个响应者

注意:
确保在设备上进行测试。模拟器会让它看起来像代码不起作用。

推荐答案

Screenlock在iOS5中已经改变了,它现在将您的应用程序发送到后台,因此如果您希望继续播放音频,则必须将audio作为UIBackGroundModes添加到Info.plist文件中。

Screenlock has changed in iOS5, it now sends your app to the background, so if you want your audio to continue you must add "audio" as a UIBackGroundModes to your Info.plist file.

最接近我的事情可以找到这方面的文件是一些
Apple devforum 帖子(需要登录)。

The closest thing I can find to documentation of this are a few Apple devforum posts (login required).

这篇关于即使类别为AVAudioSessionCategoryPlayback,AVAudioPlayer也会停止在屏幕锁定上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆