Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController initialPlaybackTime property not working in iOS 8.4

After setting initialPlaybackTime property, the video(HTTP streaming) still plays from the beginning.

The same code works well in iOS <= 8.3:

 self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];
like image 769
freestyler Avatar asked Jul 01 '15 16:07

freestyler


1 Answers

This works for me, basically you need to setCurrentPlaybackTime when the movie starts playing, But you also need a flag playbackDurationSet which is set to NO when you present movieplayer and it is set to YES when the movie is seeked to the playbackDuration for the first time.

NOTE: this flag is required because when you seek the movie from the seek scrubber the moviePlayerPlaybackStateChanged is fired with playbackState of MPMoviePlaybackStatePlaying.

BOOL playbackDurationSet = NO;
- (void)moviePlayerPlaybackStateChanged:(NSNotification*)notification
{
    MPMoviePlayerController* player = (MPMoviePlayerController*)notification.object;
    switch ( player.playbackState ) {
        case MPMoviePlaybackStatePlaying:
        if(!playbackDurationSet){
           [self.moviePlayer setCurrentPlaybackTime:yourStartTime];
           playbackDurationSet = YES;
        }
        break;
    }
}

- (void)moviePlayerPresented
{
      playbackDurationSet = NO;
}
like image 95
hariszaman Avatar answered Nov 03 '22 21:11

hariszaman