简体   繁体   English

即使设备被锁定,如何在AVQueuePlayer中循环播放歌曲队列?

[英]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将终止它。

Look at the document and ask for permission. 查看文档并征得许可。

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.

相关问题 如何在AVQueuePlayer中循环声音队列? - How do I loop the queue of sounds in AVQueuePlayer? 如何在 SwiftUI 上的 AVQueuePlayer 中获得每首歌曲之间的延迟? - How to get delay between each songs in AVQueuePlayer on SwiftUI? 即使设备锁定了方向,如何进行方向检测 - How to do Orientation Detection even the device has locked orientation 完成后如何使用 AVQueuePlayer 循环播放视频 - How to loop videos with AVQueuePlayer after it completes 即使方向被锁定,我如何检测设备方向 - How can i detect device orientation even if the orientation is locked iOS-AVQueuePlayer无法播放歌曲,有时会崩溃应用程序,当我使用移动数据时 - iOS - AVQueuePlayer is not playing the songs and sometimes it is crashing the application When i use mobile data 即使设备已锁定,仍继续播放 iframe - Contintue to play iframe even though device locked AVQueuePlayer:循环队列中的最后一项(并消除打嗝)或循环播放视频的最后几秒 - AVQueuePlayer: Loop last item in a queue (and eliminate hiccup) or loop last seconds of a video NSTimer在设备锁定时到期 - NSTimer expires when the device is locked 锁定iOS设备后,如何启用对NSURLCredentials的访问? - How can I enable access of NSURLCredentials when an iOS Device is locked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM