我曾尝试在AVPlayer和MPMoviePlayerController上播放500 KB视频,但它们都有一点点烦人的延迟。 AVPlayer和MPMoviePlayerController都显示黑屏2-3秒,然后启动视频。那真的很烦人,为什么视频开始需要这么长时间?我该如何解决?
//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 :(得分:0)
您可以预加载AVPlayer
并观察其status
。一旦更改AVPlayerStatusReadyToPlay
,您就可以毫不拖延地开始播放。