Kostia Kim
Kostia Kim

Reputation: 479

iOS > possible play a partially downloaded video?

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?

Upvotes: 3

Views: 1173

Answers (1)

Squatch
Squatch

Reputation: 1027

I am going to assume you are using MPMoviePlayerController for your video...

MPMoviePlayerController has a loadState property that you can monitor with this notification. Check to see if the video has been downloaded to a playable extent and then play.

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

}

And this is very important: If you are trying to download a video more than 10 ten minutes long, you will need to use HTTP Live Streaming.

Upvotes: 1

Related Questions