2015-04-06 73 views
0

我試過在AVPlayer和MPMoviePlayerController上播放500 KB的視頻,並且它們都有一個令人討厭的延遲。 AVPlayer和MPMoviePlayerController都會顯示一個2-3秒的黑屏,然後啓動視頻。這真的很煩人,視頻如何開始這麼久?我該如何解決它?Objective-C如何立即在MPMoviePlayerController或AVPlayer上播放視頻,而不是延遲?

//Movie Player Code 
_moviePlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:video]; 
    _moviePlayerVC.moviePlayer.view.userInteractionEnabled = YES; 
    _moviePlayerVC.moviePlayer.view.multipleTouchEnabled = YES; 
    _moviePlayerVC.moviePlayer.repeatMode = MPMovieRepeatModeOne; 
    _moviePlayerVC.moviePlayer.controlStyle = MPMovieControlStyleNone; 
    _moviePlayerVC.moviePlayer.scalingMode = MPMovieScalingModeFill; 
    _moviePlayerVC.moviePlayer.view.frame = self.frame; 
    [_moviePlayerVC.moviePlayer setShouldAutoplay:YES]; 
    _moviePlayerVC.view.frame = self.frame; 

    [self addSubview:_moviePlayerVC.view]; 

//AVPlayer Code 
AVAsset *asset = [AVAsset assetWithURL:video]; 
    AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:asset]; 
    _player = [[AVPlayer alloc] initWithPlayerItem:item]; 
    _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 
    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_player]; 
    layer.frame = self.frame; 
    layer.backgroundColor = [UIColor clearColor].CGColor; 
    [layer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 
+0

嘗試了你的AVPlayer代碼,但沒有出現在屏幕上。您的代碼中是否存在addsubview或類似的聲明? – Praxiteles 2015-07-14 09:23:35

回答

0

你可以預加載AVPlayer並觀察其status。一旦它改變AVPlayerStatusReadyToPlay你應該能夠毫不拖延地開始播放。

+1

它仍然不工作,由於某種原因仍然有延遲。就像音頻在視頻顯示之前甚至開始一樣。 PS你預先加載AVPlayer是什麼意思。 – Adp 2015-04-07 04:55:39

相關問題