[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerLoadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification object:mPlayer.moviePlayer];
- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification
{
if ((mPlayer.moviePlayer.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK)
{
NSLog(@"content play length is %g seconds", mPlayer.moviePlayer.duration);
timeRemain = [NSTimeIntervalSince1970 [mPlayer.moviePlayer.duration]-[mPlayer.moviePlayer.currentPlaybackTime]];
NSLog(@"Time Remaining::%g",timeRemain);
}
}
MPMoviePlayerController duration is in seconds already. So
[mPlayer.moviePlayer.duration]-[mPlayer.moviePlayer.currentPlaybackTime]
will return the number of seconds in current time and total duration as NSTimeInterval.
-(void)updateDuration
{
int remainingDuration = mPlayer.moviePlayer.duration - mPlayer.moviePlayer.currentPlaybackTime;
if (mPlayer.moviePlayer.currentPlaybackTime != mPlayer.moviePlayer.duration ) {
[btnRemainingDuration setTitle:[NSString stringWithFormat:@"Video ends in %d seconds", remainingDuration] forState:UIControlStateNormal];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.