MPMoviePlayerController weird behavior with setCurrentPlaybackTime

I use: MPMoviePlayerControllerto display the video.

Below I put a list of thumbs from the video. When you press your thumb I want to go to a specific place in the video, using: setCurrentPlaybackTime.

I also have a timer that updates the selected finger according to the video location, using: currentPlaybackTime.

My problem: on a call: the setCurrentPlaybackTimeplayer continues to give seconds before searching for a specific second. It takes a player several seconds to reflect new seconds. At the same time, the user's experience is bad: pressing the thumb shows that it is selected for the time of the show, then the timer is updated to the previous thumb, then it returns to the finger of your choice.

I tried to use (in the timer):

if (moviePlayer.playbackState != MPMoviePlaybackStatePlaying && !(moviePlayer.loadState & MPMovieLoadStatePlaythroughOK)) return;

In order to prevent the timer from updating the selected finger for so long that the player is in the transition phase between showing the previous thumb and the new thumb, but it does not work. "PlayState" and "LoadState" seem completely fickle and unpredictable.

Any ideas?

+4
source share
1 answer

To solve this problem, how I realized this unpleasant state coverage in one of my projects. It is unpleasant and fragile, but I worked well enough for me.

I used two flags and two time intervals;

BOOL seekInProgress_; 
BOOL seekRecoveryInProgress_;
NSTimeInterval seekingTowards_;
NSTimeInterval seekingRecoverySince_;

All of the above should be the default NOand 0.0.

When starting the search:

//are we supposed to seek?
if (movieController_.currentPlaybackTime != seekToTime)
{   //yes->
    movieController_.currentPlaybackTime = seekToTime;
    seekingTowards_ = seekToTime;
    seekInProgress_ = YES;
}

:

//are we currently seeking?
if (seekInProgress_)
{   //yes->did the playback-time change since the seeking has been triggered?
    if (seekingTowards_ != movieController_.currentPlaybackTime)
    {   //yes->we are now in seek-recovery state
        seekingRecoverySince_ = movieController_.currentPlaybackTime;
        seekRecoveryInProgress_ = YES;
        seekInProgress_ = NO;
        seekingTowards_ = 0.0;
    }
}
//are we currently recovering from seeking?
else if (seekRecoveryInProgress_)   
{   //yes->did the playback-time change since the seeking-recovery has been triggered?
    if (seekingRecoverySince_ != movieController_.currentPlaybackTime)
    {   //yes->seek recovery done!
        seekRecoveryInProgress_ = NO;
        seekingRecoverySince_ = 0.0;
    }
}

, MPMoviePlayerController "". , . , AVPlayer.

+2

All Articles