15

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];
freestyler
  • 5,224
  • 2
  • 32
  • 39
  • 3
    I'm also facing the same problem, as well as not all file types can be played now. Also, here is a radar http://www.openradar.me/20762442 with problem in that component. Looks like apple broke deprecated mpmoviewplayer in that release and you have to move to AVKit – Nikita Took Jul 02 '15 at 14:50
  • setCurrenPlaybackTime also appears to be broken. – JDL Jul 10 '15 at 23:27
  • I have played around with it for a couple of hours whith no luck at all, seems like the general response form the community is that it is currently broken. – Philip Laine Jul 11 '15 at 20:12
  • I've filed a bug report to apple. No response yet. – freestyler Jul 12 '15 at 15:05

3 Answers3

6

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;
}
d4Rk
  • 6,622
  • 5
  • 46
  • 60
hariszaman
  • 8,202
  • 2
  • 40
  • 59
0

I've seen some of these issues as well. Since MPMoviePlayerController is deprecated in iOS 9, they're unlikely to be fixed.

cable_pair
  • 93
  • 6
0

hariszaman answer worked for me:

- (void)moviePlaybackStateChanged:(NSNotification*)notif
{
    //...
    if (self.videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {

        if (self.currentBookmark) {
            if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
                NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
                [self.videoPlayer setCurrentPlaybackTime:toTime];
                self.currentBookmark = nil;
            }
        }
    }

if (self.videoPlayer.playbackState == MPMoviePlaybackStatePaused) {
    //...
}

if (self.videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
    //...
}
}

also:

    - (void)configureMoviePlayer
    {
        if (self.currentBookmark) {
            if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
                // will set start after did start
            }else {
                NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
                self.videoPlayer.initialPlaybackTime = toTime;            
                self.currentBookmark = nil;
            }
        }
        else {
            self.videoPlayer.initialPlaybackTime = 0;
        }
        //...
    }

the method is_iOSatLeast84:

- (BOOL)is_iOSatLeast84
{
    // version 8.4
    NSString *version = [[UIDevice currentDevice] systemVersion];
    BOOL isAtLeast84 = [version floatValue] >= 8.35;

    return isAtLeast84;
}

Although all of this is a workaround, it gets the job done.

Durdu
  • 4,649
  • 2
  • 27
  • 47