Ich möchte die aktuelle Videowiedergabezeit erhalten, nicht die Gesamtdauer.Wie bekomme ich MPMoviePlayerViewController aktuell Spielzeit?
Mein Code ist
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerLoadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification {
if ((self.moviePlayer.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK) {
NSLog(@"content play length is %g seconds", self.moviePlayer.duration);
// self.lblVideoDuration.text = [NSString stringWithFormat:@"%@", self.moviePlayer.duration];
}
}
aber oben wird mir Gesamtdauer, aber ich möchte nicht, Gesamtdauer.
Wenn meine Videodauer 1 Minute beträgt und es momentan etwa 30 Sekunden dauert, möchte ich das Live-Timing abspielen.
wie kann ich das bekommen?
Ich kann Video-Wiedergabe-Timing durch Start-Timer wie folgt bekommen.
- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification {
if (self.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
[self.activityIndicator stopAnimating];
[self.activityIndicator removeFromSuperview];
[self startDurationTimer];
}
}
- (void)startDurationTimer {
self.durationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(monitorMoviePlayback) userInfo:nil repeats:YES];
}
- (void)stopDurationTimer {
dispatch_async(dispatch_get_main_queue(), ^{
[self.durationTimer invalidate];
self.durationTimer = nil;
});
}
- (void)monitorMoviePlayback {
double currentTime = floor(self.moviePlayer.currentPlaybackTime);
double totalTime = floor(self.moviePlayer.duration);
double minutesElapsed = floor(currentTime/60.0);
double secondsElapsed = fmod(currentTime, 60.0);
NSLog(@"Minute = %f && Second = %f", minutesElapsed, secondsElapsed);
}
}
aber wenn ich stopptimer-Methode aufrufen, wird Timer nicht ungültig oder nicht gestoppt.
Wie kann ich den Timer ungültig machen?
Denny überprüfen Sie meine Antwort unter – user3182143