Allow “auto lock” while video is being played

前端 未结 2 487
甜味超标
甜味超标 2020-12-09 13:54

No matter whether I am using MPMoviePlayerController or AVPlayer (AVFoundation), the iOS does not allow the device to auto lock

相关标签:
2条回答
  • 2020-12-09 14:38

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

    Tested on iOS 9.

    AVPlayer *player = // alloc init...
    if ([player respondsToSelector:NSSelectorFromString(@"_preventsSleepDuringVideoPlayback")]) {
        [player setValue:@(NO) forKey:@"preventsSleepDuringVideoPlayback"];
    }
    
    0 讨论(0)
  • 2020-12-09 14:44

    With iOS 12 this is now possible by setting

    let player = AVPlayer()
    player.preventsDisplaySleepDuringVideoPlayback = false
    

    See: https://developer.apple.com/documentation/avfoundation/avplayer/2990522-preventsdisplaysleepduringvideop#

    0 讨论(0)
提交回复
热议问题