Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a KVO to MPMoviePlayer currentPlaybackTime?

How can I add a KVO to the currentPlaybackTime property of a MPMoviePlayer class?

like image 205
Milk78 Avatar asked Apr 26 '11 13:04

Milk78


1 Answers

You cannot add a KVO to currentPlaybackTime since the property is not explicitly declared as KVO compatible.

Instead, you could try polling the player regularly and storing the position, with code such as:

- (void) BeginPlayerPolling {
self.pollPlayerTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                                       target:self 
                                                     selector:@selector(PollPlayerTimer_tick:)
                                                     userInfo:nil 
                                                      repeats:YES];  

}

- (void) PollPlayerTimer_tick:(NSObject *)sender {
// Store current playback position
if (player.playbackState == MPMoviePlaybackStatePlaying)
    lastRecordedPlaybackTime = player.currentPlaybackTime;
}

- (void) EndPlayerPolling {
if (pollPlayerTimer != nil)
{
    [pollPlayerTimer invalidate];
    self.pollPlayerTimer = nil;
}
}
like image 144
Carlos P Avatar answered Nov 13 '22 11:11

Carlos P