How to add KVO to MPMoviePlayer currentPlaybackTime?

How to add KVO to currentPlaybackTime property of MPMoviePlayer class?

+6
source share
1 answer

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

Instead, you can regularly test the player and save the position with the code, for example:

- (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; } } 
+14
source

Source: https://habr.com/ru/post/886705/


All Articles