AVPlayer在播放完成时退出全屏 [英] AVPlayer exit fullscreen on finish playing

查看:80
本文介绍了AVPlayer在播放完成时退出全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVPlayer来显示一些视频流(具有固定的长度).问题是内容播放完毕后,播放器(如果用户已将其设置为全屏显示)仍保持全屏显示.

I am using a AVPlayer to show some video streams (with a fixed length). The problem is when the content is finished the player (if it has been set to fullscreen by the user) still remains in fullscreen.

在内容播放完毕后,有什么方法可以让播放器立即进入最小化状态?

Any way to make the player go to it's minimized state immediately after the content is finished playing?

推荐答案

要添加到longilong的答案中,

To add on to longilong's answer,

您可以使用itemDidFinishPlaying函数中的dismissViewControllerAnimated来关闭视频播放器.完成后,您还应该记住删除创建的观察者.

You could dismiss the video player with dismissViewControllerAnimated in the itemDidFinishPlaying function. You should also remember to remove the observer you created after you are done.

-(void)startPlaybackForItemWithURL:(NSURL*)url {

     // First create an AVPlayerItem
     AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];

     // Subscribe to the AVPlayerItem's DidPlayToEndTime notification.


    [[NSNotificationCenter defaultCenter] 
      addObserver:self 
        selector:@selector(itemDidFinishPlaying:) 
        name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];

    // Begin playback
    [player play]
} 

-(void)itemDidFinishPlaying:(NSNotification *) notification {
     // Will be called when AVPlayer finishes playing playerItem
     [self dismissViewControllerAnimated:YES completion:Nil]
     [[NSNotificationCenter defaultCenter] 
        removeObserver:self 
        name:AVPlayerItemDidPlayToEndTimeNotification 
        object:Nil];

}

这篇关于AVPlayer在播放完成时退出全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆