允许“自动锁定”正在播放视频 [英] Allow "auto lock" while video is being played

查看:184
本文介绍了允许“自动锁定”正在播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我使用 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.

我正在寻找替代这将使这成为可能。

I am looking for an alternative to AVPlayer that will make this possible.

类似的问题:

如何在播放视频时允许iPhone自动锁定

是否可以设置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版本。

Remember this is private API, I'm not sure if you can use it for appstore release or not.

在iOS 9上测试。

AVPlayer *player = // alloc init...
if ([player respondsToSelector:NSSelectorFromString(@"_preventsSleepDuringVideoPlayback")]) {
    [player setValue:@(NO) forKey:@"preventsSleepDuringVideoPlayback"];
}

这篇关于允许“自动锁定”正在播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆