В этом примере avPlayer является экземпляром AVPlayer.
Я построил элемент управления видео, который использует следующее:
для позиционирования ползунка используйте что-то вроде этого, чтобы получить процент воспроизведения в фильме, вам нужно будет запускать эту функцию несколько раз. Поэтому я бы запустил функцию как:
float scrubberBarLocation = (scrubberBgImageView.frame.size.width / 100.0f) * [self moviePercentage];
- (float)moviePercentage {
CMTime t1 = [avPlayer currentTime];
CMTime t2 = avPlayer.currentItem.asset.duration;
float myCurrentTime = CMTimeGetSeconds(t1);
float myDuration = CMTimeGetSeconds(t2);
float percent = (myCurrentTime / myDuration)*100.0f;
return percent;
}
Затем, чтобы обновить видео, я бы сделал что-то вроде:
- (void)updateVideoPercent:(float)thisPercent {
CMTime t2 = avPlayer.currentItem.asset.duration;
float myDuration = CMTimeGetSeconds(t2);
float result = myDuration * thisPercent /100.0f;
//NSLog(@"this result = %f",result); // debug
CMTime seekTime = CMTimeMake(result, 1);
[avPlayer seekToTime:seekTime];
}