简体   繁体   English

无法检测到全屏AVPlayerViewController过渡

[英]Can't detect fullscreen AVPlayerViewController transitions

The old "MPMoviePlayerController" that's now deprecated had a delegate for "MPMoviePlayerWillEnterFullScreen". 现在已弃用的旧“ MPMoviePlayerController”具有“ MPMoviePlayerWillEnterFullScreen”的委托。

https://developer.apple.com/documentation/foundation/nsnotification/name/1620898-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. 浏览文档后,找不到与当前标准“ AVPlayerViewController”相似的内容。

https://developer.apple.com/documentation/avkit/avplayerviewcontrollerdelegate 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? 基于播放器全屏切换时,如何为AVPlayerViewController实现委托?

thanks. 谢谢。

I don't believe there's any built in notification as you mentioned. 我不相信您提到过任何内置通知。 You could observe changes to the videoBounds of the AVPlayerViewController: 您可以观察到对AVPlayerViewController的videoBounds的更改:

    [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. 正如我在此处的评论所指出的那样,旋转很可能也会导致videoBounds发生变化,因此您需要在逻辑中加以考虑。

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

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