2012-07-18 35 views
1

我只想要一個連續循環的視頻。我設置了播放器這樣的:MPMoviePlayerController循環的問題

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:someURL]; 
self.moviePlayer.controlStyle = MPMovieControlStyleNone; 
self.moviePlayer.shouldAutoplay = YES; 
self.moviePlayer.repeatMode = MPMovieRepeatModeOne; 
self.moviePlayer.view.frame = self.container.frame; 
[self.container addSubview:self.moviePlayer.view]; 

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(moviePlayBackDidFinish:) name: MPMoviePlayerPlaybackStateDidChangeNotification 
              object: self.moviePlayer]; 

- (void) moviePlayBackDidFinish:(NSNotification*)notification { 

    NSLog(@"myMovieFinishedCallback: %@", notification); 
    MPMoviePlayerController *movieController = notification.object; 
    NSLog(@"player.playbackState = %d", movieController.playbackState); 
} 

的通知方法是一個簡單的黑客工具,有人建議在這裏:Smooth video looping in iOS

我有兩個問題。視頻循環仍然不是無縫的。循環之間有一個非常明顯的暫停。其次,視頻在任意數量的循環之後停止循環。通常在2-4個循環之間變化。這顯然是我的應用程序的一個巨大問題。玩家真的是這個馬車還是我做錯了什麼?

+0

是的,我相信這個播放器非常麻煩(特別是在播放開始的時候)。也就是說,你可能想在你鏈接的問題中嘗試@cmatsumoto的回答。 – 2012-07-20 13:02:17

回答

-1

我也無法使用MPMoviePlayerController獲得無間隙循環 - 總是至少有0.5s的黑色,偶爾會出現QuickTime標誌的閃爍。

但是,我能夠獲得使用AVPlayer無縫循環 - 它需要幾個條件來實現,雖然:

  1. 一些關於我的測試視頻剪輯的編碼意味着尋求開頭在每個循環的開始時總會導致約0.5秒的暫停。尋求1s到kCMTimeZero公差的剪輯使其無縫。如果沒有明確的零查找容限,則效果與查找片段開頭的效果相同。

  2. 尋找而不是玩是不穩定的;它使我的iPhone 4一掛,但不是我的iPad 3.兩種可供選擇的修復(如圖#if「低於ED),是:

    1. 等待尋求再次調用play之前完成,或者

    2. 等到特定時間(剪輯結束之前),然後重新開始播放。

下面的代碼實現這兩個條件:

self.player = [AVPlayer playerWithURL:url]; 

    self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 
    self.playerLayer.frame = self.view.bounds; 
    [self.view.layer addSublayer:self.playerLayer]; 

    [self.player seekToTime:CMTimeMakeWithSeconds(1, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; 
    [self.player play]; 

#if 1 
    [[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 
    [self.player seekToTime:CMTimeMakeWithSeconds(1, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) { 
     [self.player play]; 
    }]; 
    }]; 
#endif 

#if 0 
    NSArray *times = [NSArray arrayWithObject:[NSValue valueWithCMTime:CMTimeMake(5, 1)]]; 
    [self.player addBoundaryTimeObserverForTimes:times queue:NULL usingBlock:^{ 
    [self.player seekToTime:CMTimeMakeWithSeconds(1, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; 
    }]; 
#endif 
+0

在iOS 4到6上對我來說沒有無縫循環。試了兩個選項。 – daveMac 2012-10-18 13:58:07

0

我已經創建了一個完整的無縫循環的視頻在這裏seamless-video-looping-on-ios解決方案。隨意下載示例xcode應用程序,並親自嘗試一下,看看我的行動方式。我發現MPMoviePlayerController和AVPlayer都無法爲這種類型的工作。