refer below code: this code is some part of Apple Sample code
AVPlayerDemo
If you try to implement a streaming player, refer to the sample code below.
StitchedStreamPlayer
also, a complete implements to exactly scrub is to using the like slider below.
because great Video Player is should be considering UX. as you know running default Video App. as you scrubbing, if drag down slider must be fine tuning.
CPSlider
| OBSlider
/* The user is dragging the movie controller thumb to scrub through the movie. */
- (IBAction)beginScrubbing:(id)sender
{
mRestoreAfterScrubbingRate = [mPlayer rate];
[mPlayer setRate:0.f];
/* Remove previous timer. */
[self removePlayerTimeObserver];
}
/* Set the player current time to match the scrubber position. */
- (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)];
}
}
}
/* The user has released the movie thumb control to stop scrubbing through the movie. */
- (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;
}
}