iPhone 背景音频开/关
我有一个应用程序,可以在应用程序位于后台且条目位于 plist 中时播放音频,并且一切正常。 但我想为用户提供设置背景播放打开和关闭的选项 我使用此方法来激活播放器,
moviePlayer.useApplicationAudioSession = YES;
[moviePlayer play];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
[[AVAudioSession sharedInstance] setActive:YES error:NULL];
我想在运行时更改此选项,并且不会中断音频播放。 如果这可能发生,有什么想法吗?
感谢您的宝贵时间,
我将在这里发布解决方案以使其更好
if (backgroundSwitch.on) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
}else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:NULL];
}
I have an application that can play audio while the application is in the background with the entry in the plist and everything work fine.
But I would like to give the option to the user to setup the background play on and off
I use this method to activate the player
moviePlayer.useApplicationAudioSession = YES;
[moviePlayer play];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
[[AVAudioSession sharedInstance] setActive:YES error:NULL];
I would like to change this option on run time and without any interruptions to the audio play.
Any ideas if this can happen?
Thanks for your time
I will post the solution here to make it better
if (backgroundSwitch.on) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
}else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:NULL];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论