[英]How to loop a queue of songs in AVQueuePlayer even when device is locked?
I already have a looping implementation, and it works when the device is open. 我已经有一个循环实现,它在设备打开时有效。 I listen for the AVPlayerItem.DidPlayToEndTimeNotification and handle the looping in that Callback.
我监听AVPlayerItem.DidPlayToEndTimeNotification并处理该回调中的循环。 But as soon as the device is locked, it the AVQueuePlayer does not play.
但是一旦设备被锁定,AVQueuePlayer就无法播放。 Is this somehow related to iOS backgrounding and how apps function when backgrounded?
这是否与iOS背景以及应用程序在后台运行时的功能有何关联?
Normally, Apple does not allow apps to run in background. 通常,Apple不允许应用程序在后台运行。 If you want to play a song in background, you should set the
Required Background Modes
property in the application's Info.plist
. 如果要在后台播放歌曲,则应在应用程序的
Info.plist
设置“ Required Background Modes
属性。
Audio - Music players and other applications that work with audio content may be registered to continue playing audio even when the app is no longer in the foreground.
音频 - 音频播放器和其他使用音频内容的应用程序可能会被注册,即使应用程序不再位于前台,也可以继续播放音频。 If an app in this category attempts to do anything other than play audio or download while in the background, iOS will terminate it.
如果此类别中的应用尝试在播放音频或在后台下载时执行任何操作,iOS将终止它。
I fixed the problem. 我解决了这个问题。 When an AVPlayer stops playing, the app is suspended by iOS even with Background Modes enabled.
当AVPlayer停止播放时,即使启用了后台模式,iOS也会暂停该应用。 My looping logic is implemented right after the AVPlayer plays the last item so it doesn't get executed in the background.
我的循环逻辑在AVPlayer播放最后一项后立即实现,因此它不会在后台执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.