我試過在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];
嘗試了你的AVPlayer代碼,但沒有出現在屏幕上。您的代碼中是否存在addsubview或類似的聲明? – Praxiteles 2015-07-14 09:23:35