假设我们正在下载一个大型视频 - 它的50Mb - 但到目前为止只下载了25Mb - 是否有可能在完全下载之前开始播放视频?
答案 0 :(得分:1)
我假设您正在为视频使用MPMoviePlayerController ......
MPMoviePlayerController有一个loadState属性,您可以使用this notification进行监视。检查视频是否已下载到可播放范围,然后播放。
//Begin observing the moviePlayer's load state.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];
- (void)moviePlayerLoadStateChanged:(NSNotification *)notification{
//NSLog(@"State changed to: %d\n", moviePlayer.loadState);
if(moviePlayer.loadState == MPMovieLoadStatePlayable && [videoIndicator isAnimating]){
//if load state is ready to play
[videoIndicator stopAnimating];//Pause and hide the indicator
[self.contentView addSubview:[moviePlayer view]];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer play];//play the video
}
}
这一点非常重要:如果您要下载超过10分钟的视频,则需要使用HTTP Live Streaming。