我有一个播放视频的AVPlayer对象,但是
- (void)playerItemDidReachEnd:(NSNotification *)notification
方法永远不会被调用。因为我完全按照Apple的文档,不确定我做错了什么。这是我的代码:
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
[self.playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];//This works okay
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.playerItem];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
[self.playerLayer setFrame:[[[self playerView] layer] bounds]];
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.playerLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
[self.playerLayer setHidden:NO];
[[[self playerView] layer] addSublayer:self.playerLayer];
答案 0 :(得分:0)
在您的代码中注册playerItemDidReachEnd:作为回调,最后一行应为:
object:self.player
不是playerItem