How to allow iPhone auto-lock while playing a vide

2020-03-30 02:59发布

问题:

How can I allow iOS device to dim screen and auto-lock the device while playing a video with AVFoundation. Playing a video with AVPlayer disable screen auto-lock by default. Is there anyway to re-enable it without pausing the video play.

回答1:

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.



回答2:

I worked on the application where we used AVPlayer to display video backgrounds in application. 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.