【发布时间】:2012-07-03 06:46:43
【问题描述】:
假设我们正在下载一个大视频 - 它的大小为 50Mb - 但到目前为止只下载了 25Mb - 是否可以在视频完全下载之前开始播放?
【问题讨论】:
标签: ios video asihttprequest
假设我们正在下载一个大视频 - 它的大小为 50Mb - 但到目前为止只下载了 25Mb - 是否可以在视频完全下载之前开始播放?
【问题讨论】:
标签: ios video asihttprequest
我假设您正在为您的视频使用 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。
【讨论】: