3

Say we are downloading a large video - its 50Mb - but only 25Mb has downloaded so far - is it possible to start playing the video before its completely downloaded?

4

1 回答 1

1

我将假设您正在为您的视频使用 MPMoviePlayerController ...

MPMoviePlayerController 有一个 loadState 属性,您可以使用此通知对其进行监视。检查视频是否已下载到可播放范围,然后播放。

//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

于 2012-07-03T13:53:16.070 回答