15

设置 initialPlaybackTime 属性后,视频(HTTP 流)仍然从头开始播放。

相同的代码在 iOS <= 8.3 中运行良好:

 self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];
4

3 回答 3

6

这对我有用,基本上你需要在电影开始播放时设置CurrentPlaybackTime,但是你还需要一个标志playbackDurationSet ,当你展示movieplayer时它设置为NO,当电影第一次被寻找到playbackDuration时它设置为YES .

注意:此标志是必需的,因为当您从搜索擦除器中搜索电影时,moviePlayerPlaybackStateChanged会以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;
}
于 2015-07-13T09:26:59.817 回答
0

我也看到了其中一些问题。由于 MPMoviePlayerController 在 iOS 9 中已被弃用,因此它们不太可能被修复。

于 2015-07-13T17:47:47.367 回答
0

哈里萨曼回答对我有用:

- (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) {
    //...
}
}

还:

    - (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;
        }
        //...
    }

方法是_iOSatLeast84:

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

    return isAtLeast84;
}

尽管所有这些都是一种解决方法,但它可以完成工作。

于 2015-07-21T08:46:34.000 回答