简体   繁体   中英

Can't detect fullscreen AVPlayerViewController transitions

The old "MPMoviePlayerController" that's now deprecated had a delegate for "MPMoviePlayerWillEnterFullScreen".

https://developer.apple.com/documentation/foundation/nsnotification/name/1620898-mpmovieplayerwillenterfullscreen

Can't find anything similar for the current standard, "AVPlayerViewController" after looking through the docs.

https://developer.apple.com/documentation/avkit/avplayerviewcontrollerdelegate

How do I implement a delegate for AVPlayerViewController when based on the toggling of fullscreen of the player?

thanks.

I don't believe there's any built in notification as you mentioned. You could observe changes to the videoBounds of the AVPlayerViewController:

    [self.playerViewController addObserver:self forKeyPath:@"videoBounds" options:0 context:NULL];

Then use your own logic once the observation comes in to determine whether it was toggled to full screen or another bounds change:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (object == self.playerViewController && [keyPath isEqualToString:@"videoBounds"]) {
        // check your playerViewController videoBounds here compared to what they were previously
        // they could change outside of toggleFullScreen (rotation for example)
    }
}

As noted in my comments there, rotation will most likely cause a videoBounds change as well so you'll need to account for that in your logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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