Seema Seema - 3 months ago 22
iOS Question

How to Count Video playing remaining Time in iOS?

[[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);
}
}

Answer

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.

Comments