see below code: this code is part of Apple Sample Code
AVPlayerDemo
If you try to implement a streaming player, see the code example below.
StitchedStreamPlayer
In addition, a complete tool for even scrub is to use a similar slider below. because a great video player should consider UX. since you know that the Video application is working by default. how do you clean, if you drag the slider should be fine-tuning.
CPSlider | Obslider
- (IBAction)beginScrubbing:(id)sender { mRestoreAfterScrubbingRate = [mPlayer rate]; [mPlayer setRate:0.f]; [self removePlayerTimeObserver]; } - (IBAction)scrub:(id)sender { if ([sender isKindOfClass:[UISlider class]]) { UISlider* slider = sender; CMTime playerDuration = [self playerItemDuration]; if (CMTIME_IS_INVALID(playerDuration)) { return; } double duration = CMTimeGetSeconds(playerDuration); if (isfinite(duration)) { float minValue = [slider minimumValue]; float maxValue = [slider maximumValue]; float value = [slider value]; double time = duration * (value - minValue) / (maxValue - minValue); [mPlayer seekToTime:CMTimeMakeWithSeconds(time, NSEC_PER_SEC)]; } } } - (IBAction)endScrubbing:(id)sender { if (!mTimeObserver) { CMTime playerDuration = [self playerItemDuration]; if (CMTIME_IS_INVALID(playerDuration)) { return; } double duration = CMTimeGetSeconds(playerDuration); if (isfinite(duration)) { CGFloat width = CGRectGetWidth([mScrubber bounds]); double tolerance = 0.5f * duration / width; mTimeObserver = [[mPlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(tolerance, NSEC_PER_SEC) queue:NULL usingBlock: ^(CMTime time) { [self syncScrubber]; }] retain]; } } if (mRestoreAfterScrubbingRate) { [mPlayer setRate:mRestoreAfterScrubbingRate]; mRestoreAfterScrubbingRate = 0.f; } }
source share