I have a media player application that plays music using MPMoviePlayerController. I need to update the user interface based on the playback position. The best I can say is that I cannot actively get this information from a player with a callback or something else, and I basically need to interview him myself.
So I thought that I would use a simple timer that will start every second. The code is:
Somewhere in the installation code:
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updatePlaybackProgressFromTimer:) userInfo:nil repeats:YES];
And then:
- (void) updatePlaybackProgressFromTimer:(NSTimer *)timer { if (([UIApplication sharedApplication].applicationState == UIApplicationStateActive) && (player.playbackState == MPMoviePlaybackStatePlaying)) { CGFloat progress = player.currentPlaybackTime / player.duration;
}
The timer starts every second, even if the application is in the background. First, the method sees if the application is active and the player is playing, and then updates the user interface.
Is there some time to time to use the timer every second this way? Should I be more diligent and try to demolish the timer when entering the background and activate it when the application is activated? I'm sure some battery effects, but realistic, how serious is it? Or are there any other recommended ways to do such things?
source share