MPMoviePlayerViewController无法设置当前播放时间

时间:2012-03-20 11:59:28

标签: objective-c ios video mpmovieplayercontroller

我正在尝试在MPMoviePlayerViewController中设置MPMoviePlayerController的currentPlaybackTime属性,使其从当时恢复播放视频(HLS流),当应用程序重新启动时它已停止活动。这是我的代码:

    //the functinon that sets playback time
    - (void)setCurrentPlayTime:(NSNumber *)time {
        if (self.moviePlayer.currentPlaybackTime < [time floatValue] - 10.0) {
            [self.moviePlayer setCurrentPlaybackTime:(NSTimeInterval)[time floatValue]];
        }
    }

    //app did become active callback
    - (void) applicationDidBecomeActiveNotification:(NSNotification*)notification {
        if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
            [self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
        }
    }

    //player load state did change callback
    -(void)playerLoadStateDidChange:(NSNotification *)notification {   
    MPMoviePlayerController *player = notification.object;
    MPMovieLoadState loadState = player.loadState;  
if (loadState & MPMovieLoadStatePlaythroughOK) {
        if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
            [self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
            _curPlayTime = 0.0;
        }
}

当我点击“主页”按钮然后重新打开应用程序时,如果我接到来电但拒绝接听,则可以正常工作。但是,如果我接听来电,在我完成通话后,从0.0忽略的setCurrentPlaybackTime方法调用开始播放。有没有人知道,问题出在哪里,可能是一个如何正确工作的例子?

1 个答案:

答案 0 :(得分:-2)

不确定这是否是问题,但您要搜索的选择器是setCurrentPlayTime而不是setCurrentPlay * 返回 *时间。