iPhone 锁定时继续播放音频
当 iPhone 自动锁定或用户锁定手机时,如何继续在 iPhone 中播放音频?
我已经尝试过了
session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:NULL];
,但这似乎不起作用。
How can I continue an audio playback in iPhone when it auto-locks or the user locks the phone?
I already tried
session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:NULL];
but that doesn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于知道该怎么做了!
首先,将这些框架包含到您的项目中:AudioToolbox、CoreAudio、MediaPlayer 和 AVFoundation。将它们全部导入到将放置播放器的 viewController 中。分配并开始播放音频后,插入以下代码:
最后,转到应用程序 Info.plist 文件并添加名为 UIBackgroundModes 的行。新行将是一个数组,包含 1 个项目,即项目 0。为此,您只需将值设置为音频。你就完成了!享受您的背景音频播放应用程序!
I finally figured out how to do this!
First of all, include these frameworks to your project: AudioToolbox, CoreAudio, MediaPlayer and AVFoundation. Import them all to the viewController where your player will be placed. After you allocated and started playing the audio, insert the following code:
And finally, go to your app Info.plist file and add a row named UIBackgroundModes. The new row will be an array and will contain 1 item, the item 0. To this you just set the value as audio. And you're done! Enjoy you're background audio playing app!
此链接应该有所帮助。
您需要防止应用程序进入深度睡眠模式:
This link should help.
You need to prevent the app from entering a deep sleep mode: