允许“自动锁定"在播放视频时 [英] Allow "auto lock" while video is being played
问题描述
无论我使用的是MPMoviePlayerController
还是AVPlayer
(AVFoundation
),iOS 都不允许设备自动锁定(进入睡眠模式),同时视频播放.
No matter whether I am using MPMoviePlayerController
or AVPlayer
(AVFoundation
), the iOS does not allow the device to auto lock (to enter sleep mode) while the video is playing.
我有一个案例,在后台不断循环播放极慢的视频.播放此视频时,设备永远不会进入睡眠状态.
I have a case where an extremely slow video is constantly being played in a loop in the background. While this video is playing, the device never goes to sleep.
到目前为止,我唯一的选择是检测用户何时没有进行任何操作,然后暂停视频.之后,设备会倒计时 iOS 设置中指定的自动锁定"持续时间.
So far, the only option I have is to detect when a user did not make any actions for a while and then pause the video. After that, the device counts down the "auto lock" duration that is specified in iOS Settings.
我正在寻找 AVPlayer
的替代方案,这将使这成为可能.
I am looking for an alternative to AVPlayer
that will make this possible.
类似问题:
是否可以设置AVPlayer让设备在播放视频时进入睡眠状态?
如何在 MPMoviePlayer 播放期间启用 iPhone 自动锁定?
我有一个在 UIWebView
中使用 HTML5 视频的想法,但 iOS 不允许在这些视频上自动播放.
I had an idea to use HTML5 video inside a UIWebView
, but iOS does not allow autoplay on those.
推荐答案
记住这是私有 API,我不确定你是否可以将它用于 appstore 发布.
在 iOS 9 上测试.
Tested on iOS 9.
AVPlayer *player = // alloc init...
if ([player respondsToSelector:NSSelectorFromString(@"_preventsSleepDuringVideoPlayback")]) {
[player setValue:@(NO) forKey:@"preventsSleepDuringVideoPlayback"];
}
这篇关于允许“自动锁定"在播放视频时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!