6

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

Milk78
  • 239
  • 3
  • 13
  • The common way works just fine BUT it wont help you if you want to trap manipulations to the playback-time done by the player-controls (e.g. seek-slider) - those do not use the currentPlaybackTime property setter to achieve seeking. – Till May 03 '11 at 12:37
  • @Till I don't believe that you can do this, since the currentPlaybackTime is not marked as KVO compatible, and my own attempts to observe it did not result in change notifications firing. See my alternative suggestion below. – Carlos P Jun 19 '11 at 14:53
  • @Carlos Right, from the result point of view, that is what I said; it wont work. Still I was not clear enough on describing currentPlaybackTime to be non KVO-compliant. Thanks for pointing that out. – Till Jun 19 '11 at 15:12

1 Answers1

14

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;
}
}
Carlos P
  • 3,928
  • 2
  • 34
  • 50