我正在做一个申请。我用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
没有解雇。
答案 0 :(得分:0)
不是百分百肯定,但可能是因为NSNotificationCenter仍然保留对self的引用。尝试删除观察者
- (void)playerItemDidReachEnd:(NSNotification *)notification
功能。从那时起
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:nil];