观看MPMoviePlayerController后加载相同的ViewController

时间:2017-01-11 08:45:33

标签: objective-c mpmovieplayercontroller

我有一个ViewController,它显示有关所选节目的信息,MPMoviePlayerController的播放按钮就在那里。现在,问题是当我点击播放器的全屏时,然后点击完成。它应该返回到显示信息的ViewController,但事实并非如此。但是它会进入ViewController的viewDidLoad并且它根本不显示任何内容。我觉得ViewController的顶部或类似的东西

以下是我删除播放器控制器的方法

- (void)dealloc
{
self.delegate = nil;
self.activityIndicator = nil;
[self deregisterMoviePlayerNotifications];
[self.player.view removeFromSuperview];
[self removeFromSuperview];
[self stopVideo];
self.player = nil;
}

1 个答案:

答案 0 :(得分:1)

您应该使用AVPlayerViewController,因为MPMoviePlayerController已被弃用。您可以在播放按钮

上使用此代码
-(void)playButton{    
    AVPlayer *player = [[AVPlayer alloc]initWithURL:urlVideo];
    AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
    controller.player = player;
    controller.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:player.currentItem];
    controller.videoGravity = AVLayerVideoGravityResizeAspect;
    [self presentViewController:controller animated:YES completion:nil];
    [player play];
}

-(void)playerItemDidReachEnd:(NSNotification*)notification{

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self dismissViewControllerAnimated:YES completion:nil];
}

注意:不要忘记添加AVFoundation.framework