2

I'm using the MPMoviePlayer to play a movie. I want to be able to play the movie and allow the user to skip to a certain time in the film at the press of a button.

I'm setting the currentPlaybackTime property of the player but it doesn't seem to work. Instead it simply stats the movie from the beginning no matter what value I use.

Also I log the currentPlaybackTime property through a button click, it always returns a large number but it sometimes returns a minus value?! is this expected? (e.g. -227361412)

Sample code below:

- (IBAction) playShake 
{   
        NSLog(@"playback time = %d",playerIdle.currentPlaybackTime);    
        [self.playerIdle setCurrentPlaybackTime:2.0];
        return;
}
Dhara
  • 4,093
  • 2
  • 36
  • 69
bennythemink
  • 5,096
  • 4
  • 36
  • 54

2 Answers2

4

I have successfully used this method of skipping to a point in a movie in the past. I suspect that your issue is actually with the video itself. When you set the currentPlaybackTime MPMoviePlayer will skip to the nearest keyframe in the video. If the video has few keyframes or you're only skipping forward a few seconds this could cause the video to start over from the beginning when you change the currentPlaybackTime.

Fireandlight27
  • 716
  • 5
  • 9
  • Thanks for the info Fireandlight27. In the end I decided to use a different method and its working the way I want it too. I wrote an explanation here: http://stackoverflow.com/questions/4560065/mpmovieplayercontroller-switching-movies-causes-white-flash – bennythemink Mar 01 '11 at 22:11
2

-currentPlaybackTime returns a NSTimeInterval (double) which you are printing as a signed int. This will result in unexpected values. Try either casting to int (int)playerIdle.currentPlaybackTime or printing the double %1.3f.

Grimless
  • 1,268
  • 1
  • 15
  • 30
  • Ah yes, stupid mistake on my part regarding the logging. Thanks for the advice. It now logs the correct time stamp but I'm still at a loss for setting the currentPlaybackTime. It just restarts the movie :( – bennythemink Feb 21 '11 at 03:45
  • Setting the playback time to -2.0? The value is likely clamped to 0. Negative playback times likely start the movie over. You might by trying to do something like `[self.playerIdle setCurrentPlaybackTime:([self.playerIdle currentPlaybackTime] - 2.0)];`? – Grimless Feb 21 '11 at 03:58
  • fook, im tired. it was a typo when writing the code here, the minus 2 is not in the actual project, just in my dumb description. – bennythemink Feb 21 '11 at 05:07