Reputation: 1675
I am trying to set currentPlaybackTime property of the MPMoviePlayerController in MPMoviePlayerViewController to make it resume playing video (HLS stream) from the time, it was stopped when the app resigned active. Here's my code:
//the functinon that sets playback time
- (void)setCurrentPlayTime:(NSNumber *)time {
if (self.moviePlayer.currentPlaybackTime < [time floatValue] - 10.0) {
[self.moviePlayer setCurrentPlaybackTime:(NSTimeInterval)[time floatValue]];
}
}
//app did become active callback
- (void) applicationDidBecomeActiveNotification:(NSNotification*)notification {
if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
[self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
}
}
//player load state did change callback
-(void)playerLoadStateDidChange:(NSNotification *)notification {
MPMoviePlayerController *player = notification.object;
MPMovieLoadState loadState = player.loadState;
if (loadState & MPMovieLoadStatePlaythroughOK) {
if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
[self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
_curPlayTime = 0.0;
}
}
When I just tap Home button and then reopen the app, and also if I get incoming call but decline it, it works. But if I answer an incoming call, after I finish the call, playing starts from the 0.0 ignoring setCurrentPlaybackTime method call. Does anybody know, where's the problem and may be any example how it should be done to work correct?
Upvotes: 1
Views: 2945
Reputation: 1321
Not sure if this is the issue but the selector you are searching for is setCurrentPlayTime not setCurrentPlay*back*Time.
Upvotes: -2