2012-09-02 36 views
0

我環路我的視頻玩視頻AVFoundation與NSNotificationCenter和playerItemDidReachEnd的幫助:爲什麼我不能依靠NSNotificationCenter使用AVFoundation來循環播放視頻?

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; 
    self.playerItem = [AVPlayerItem playerItemWithAsset:asset]; 
    self.avPlayer = [AVPlayer playerWithPlayerItem:self.playerItem]; 

    [self.avPlayer  addObserver:self forKeyPath:@"status" 
         options:0 context:AVMoviePlayerViewControllerStatusObservationContext]; 
    [[NSNotificationCenter defaultCenter]   addObserver:self 
                selector:@selector(playerItemDidReachEnd:) 
                name:AVPlayerItemDidPlayToEndTimeNotification 
                object:[self.avPlayer currentItem]]; 

    [self.VideoView setPlayer:self.avPlayer]; 

- (void)playerItemDidReachEnd:(NSNotification *)notification {   
     [notification.object seekToTime:kCMTimeZero]; 
     [self startVideoLoop]; 
} 

的偉大工程 - 但不幸的是不可靠的。有些時候沒有任何邏輯的原因(在我看來),玩家停在電影的末尾而不重新開始。

是否有可能NSNotificationCenter錯過了電影的結尾或方法playerItemDidReachEnd錯過了通知消息? 愚蠢的問題。但我無法做頭,也沒有它的尾巴......

回答

0

答案北京時間

self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; // default: AVPlayerActionAtItemEndPause 
相關問題