1
我有一個是播放視頻罰款的AVPlayer對象,但是AVPlayer playerItemDidReachEnd:通知從不叫(OS X)
- (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];
應該是,[self.player CURRENTITEM] – user023
@DavidElliman你錯了,你有沒有讀過AVPlayerDemo上的Apple示例代碼? – onmyway133