简体   繁体   English

当应用程序处于后台时,是否无法更改 AVPlayer 或 AVQueuePlayer 中的播放器项目

[英]Is it impossible to change the player item(s) in an AVPlayer or in an AVQueuePlayer while app is in Background

I was using an AVPlayer to stream remote audio files.我正在使用 AVPlayer 来流式传输远程音频文件。 When an item ended, i would load up a new item into the AVPlayer and then start playing again.当一个项目结束时,我会将一个新项目加载到 AVPlayer 中,然后再次开始播放。 This worked well in both foreground and in the background in iOS 9.2 .这在 iOS 9.2 的前台和后台都运行良好。 With the release of iOS 9.3 this method no longer worked.随着 iOS 9.3 的发布,这种方法不再有效。 I had to switch over to using an AVQueuePlayer in order to ensure that when a song ended the audio would continue to the next song.我不得不切换到使用 AVQueuePlayer 以确保当一首歌曲结束时音频会继续播放下一首歌曲。

My issue now is that there are scenarios in my app that require the AVQueuePlayer, or the AVPlayer to get a new URL and load it into the player then begin playing it, all while in the background.我现在的问题是我的应用程序中有一些场景需要 AVQueuePlayer 或 AVPlayer 获取新 URL 并将其加载到播放器中,然后开始播放,同时在后台进行。 This was working fine in iOS 9.2 but now with 9.3 it just stopped working.这在 iOS 9.2 中运行良好,但现在在 9.3 中它停止工作。

Does anybody know why this stopped working and how to fix it?有谁知道为什么这停止工作以及如何解决它? Is it common for Apple to make a change like this and not mention anything about it?苹果公司做出这样的改变而不提及任何事情是很常见的吗?

Update: I have even tried a hack, where i begin playback of a second player, while the first one loads a new item from a new URL, so that audio never stops.更新:我什至尝试了一个 hack,我开始播放第二个播放器,而第一个播放器从新 URL 加载一个新项目,这样音频就不会停止。 This also didnt work.这也不起作用。

By adding the line通过添加行

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()

to view did load...this solved the problem...查看确实加载...这解决了问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM