[[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);
}
}
答案 0 :(得分:2)
MPMoviePlayerController持续时间已经过了几秒钟。 所以
[mPlayer.moviePlayer.duration]-[mPlayer.moviePlayer.currentPlaybackTime]
将以NSTimeInterval的形式返回当前时间和总持续时间的秒数。
答案 1 :(得分:0)
-(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];
}
}