2013-07-01 47 views
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]; 

回答

0

在您的代碼註冊playerItemDidReachEnd:作爲回調的最後一行應該是:

object:self.player 

不是playerItem

+0

應該是,[self.player CURRENTITEM] – user023

+0

@DavidElliman你錯了,你有沒有讀過AVPlayerDemo上的Apple示例代碼? – onmyway133