How can I add a KVO to the currentPlaybackTime property of a MPMoviePlayer class?
Asked
Active
Viewed 2,536 times
6
-
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 Answers
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
-
-
@Milk78 Yes, it seems to be the only way of tracking the position at the moment. Thanks for accepting the answer. – Carlos P Jun 27 '11 at 23:08
-
@BenScheirman I know, I'm slightly ashamed of it - but seems it's the only solution for now – Carlos P Dec 07 '11 at 12:56
-
Why we don't have any "addPeriodicTimeObserverForInterval:" like in AVPlayer ? – Paweł Brewczynski Dec 22 '14 at 04:16