简体   繁体   English

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

[英]How to allow iPhone auto-lock while playing a video

How can I allow iOS device to dim screen and auto-lock the device while playing a video with AVFoundation. 在使用AVFoundation播放视频时,如何允许iOS设备变暗屏幕并自动锁定设备。 Playing a video with AVPlayer disable screen auto-lock by default. 默认情况下,使用AVPlayer播放视频会禁用屏幕自动锁定。 Is there anyway to re-enable it without pausing the video play. 无论如何,在不暂停视频播放的情况下是否可以重新启用它。

why you want screen to go idle while playing video? 为什么要在播放视频时使屏幕空闲? The real answer is it can't be done. 真正的答案是无法完成。 Following are just work arounds with serious downsides. 以下只是存在严重弊端的解决方法。

The only method apple allows us to use is 苹果允许我们使用的唯一方法是

[UIApplication sharedApplication].idleTimerDisabled

You can dim screen programmatically by using a UIView with color black and slowly changing it alpha property to create the illusion of screen going idle. 您可以通过使用具有黑色的UIView并通过缓慢更改其alpha属性来以编程方式使屏幕变暗,以创建屏幕进入空闲状态的错觉。

I worked on the application where we used AVPlayer to display video backgrounds in application. 我在应用程序上工作,我们使用AVPlayer在应用程序中显示视频背景。 Our solution was to stop video after some idle time. 我们的解决方案是在闲置一段时间后停止视频。 I mean implementing idle timer on our side. 我的意思是在我们这边实现空闲计时器。 And then send message to all background players to stop them. 然后向所有后台播放器发送消息以阻止他们。 It's the only good workaround I know. 这是我知道的唯一好的解决方法。

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

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