AVPlayerviewcontroller没有消失

时间:2016-12-20 07:03:01

标签: ios iphone avplayerviewcontroller

我正在做一个申请。我用AVPlayerViewController来播放视频。但是播放视频后它并没有被解雇。

请查看我的来源:

 _player = [AVPlayer playerWithURL:self.videoURL];
        _avVideoController = [[AVPlayerViewController alloc]init];
        _avVideoController.view.frame = self.view.frame;
        _avVideoController.delegate =self;
        _avVideoController.player.actionAtItemEnd = AVPlayerActionAtItemEndAdvance;
        _avVideoController.player = _player;
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(playerItemDidReachEnd:)
                                                     name:AVPlayerItemDidPlayToEndTimeNotification
                                                   object:[_avVideoController.player currentItem]];
        [_player play];
        [self.view addSubview:_avVideoController.view];
        [self presentViewController:_avVideoController animated:YES completion:nil];


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

[_avVideoController dismissViewControllerAnimated:YES completion:nil];
[_avVideoController.view removeFromSuperview];
NSLog(@"IT REACHED THE END");

 }

此后AVPlayerViewController没有解雇。

1 个答案:

答案 0 :(得分:0)

不是百分百肯定,但可能是因为NSNotificationCenter仍然保留对self的引用。尝试删除观察者  - (void)playerItemDidReachEnd:(NSNotification *)notification功能。从那时起

[[NSNotificationCenter defaultCenter] removeObserver:self 
                                                name:AVPlayerItemDidPlayToEndTimeNotification 
                                              object:nil];