MPMoviePlayerController initialPlaybackTime property not working in iOS 8.4
Asked Answered
P

3

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];
Probability answered 1/7, 2015 at 16:3 Comment(4)
I'm also facing the same problem, as well as not all file types can be played now. Also, here is a radar openradar.me/20762442 with problem in that component. Looks like apple broke deprecated mpmoviewplayer in that release and you have to move to AVKitMadge
setCurrenPlaybackTime also appears to be broken.Amata
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.Academic
I've filed a bug report to apple. No response yet.Probability
I
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;
}
Inquietude answered 13/7, 2015 at 9:26 Comment(0)
R
0

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

Ridicule answered 13/7, 2015 at 17:47 Comment(0)
B
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.

Blameless answered 21/7, 2015 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.