1

我有一个可以正常播放视频的 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];
4

1 回答 1

0

在您注册 playerItemDidReachEnd: 作为回调的代码中,最后一行应该是:

object:self.player

不是 playerItem

于 2013-09-13T14:18:24.567 回答