2016-08-20 65 views
-1

我需要一些帮助,像藤一样的无限视频循环。 我尝试了很多方法,他们都有一个短暂的延迟。Vine的无限视频循环在iOS 9(无缝视频)

一个最流行的:

__weak typeof(self) weakSelf = self; // prevent memory cycle 
    NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; 
[noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification 
        object:nil // any object can send 
        queue:nil // the queue of the sending 
       usingBlock:^(NSNotification *note) { 
        // holding a pointer to avPlayer to reuse it 
        [weakSelf.avPlayer seekToTime:kCMTimeZero]; 
        [weakSelf.avPlayer play]; 
       }]; 

有什么办法来消除延迟和无缝播放本地视频?

我知道苹果在iOS中9添加一些更新,但我需要它从8+ IOS

对不起OJC-C样品,我用斯威夫特

回答

0

工作试试这个

-(void)startPlaybackForItemWithURL:(NSURL*)url { 

// First create an AVPlayerItem 
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url]; 

// Subscribe to the AVPlayerItem's DidPlayToEndTime notification. 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; 

// Pass the AVPlayerItem to a new player 
self.avPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem]; 

// Begin playback 
[player play] 

} 

-(void)itemDidFinishPlaying:(NSNotification *) notification { 
    [self.avPlayer play]; 
    // Will be called when AVPlayer finishes playing playerItem 
}