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.
Asked
Active
Viewed 7,055 times
2
-
when you say auto lock do you mean that its locks the iPhone and goes to the lock screen? – MCKapur Apr 22 '12 at 12:16
-
Haven't been able to do it myself and I still don't know if there is a way to do it. Just as a comment... After you pause the `AVPlayer`, the auto-lock duration starts counting down. When it expires, the device goes to sleep mode. – AndroC Jun 10 '15 at 12:44
-
http://stackoverflow.com/questions/30760826/allow-auto-lock-while-video-is-being-played – AndroC Jun 10 '15 at 15:43
-
See my answer here : http://stackoverflow.com/a/38018555/1017340 – Mojtaba Jun 24 '16 at 16:57
2 Answers
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.

Shaheen M Basheer
- 1,010
- 6
- 11
-
3"You can dim screen programmatically by using a UIView with color black" - seriously? It will not prevent battery drain. – Timur Bernikovich Jul 12 '17 at 15:26
-
This API will not work with AVPlayer, this answer is wrong. The real answer is it can't be done – Kyle Redfearn Mar 28 '18 at 20:13
0
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.

Timur Bernikovich
- 5,660
- 4
- 45
- 58