问题
i want to calculate current time based on how much video is played, i am confused to use the property of durationWatched, can any one help me what should i do? or how to get current time of youtube video?
回答1:
I have made a simple category on MPMoviePlayerController
You can get the current playback time using the currentTimeMonitor method:
[self.moviePlayerController currentTimeMonitor:^{
NSLog(@"Current time %i",[moviePlayerController.lastRecordedPlaybackTime intValue]);
}];
A timer call the block every second to give you the current playbacktime.
There is a repository on github:
https://github.com/AlbanPerli/MPMoviePlayerController-CurrentPlybackTimeMonitor
回答2:
try below code
CGFloat currentPlayedTime = [movieController currentPlaybackTime];
hope its helpfull.
回答3:
It may be helpful . Take the dates When it is started and stopped then do this .
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"HH:mm"];
NSDate *date1 = [df dateFromString:@"14:10"];// Startdate
NSDate *date2 = [df dateFromString:@"18:09"];// Stop date
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
int hours = (int)interval / 3600; // integer division to get the hours part
int minutes = (interval - (hours*3600)) / 60; // interval minus hours part (in seconds) divided by 60 yields minutes
NSString *timeDiff = [NSString stringWithFormat:@"%d:%02d", hours, minutes];
来源:https://stackoverflow.com/questions/18400342/mpmoviewplayer-calculate-current-time-during-video-play