IOS AVPlayer - lock at specific points

I more or less use the code from here: AVPlayer Video SeekToTime However, when I try to scroll, it seems to block at certain points in time (basically every frame that lies in the second timestamp), so when I brush through scrubber, he continues to shoot back and forth between where my finger is, and the last second and the video only changes to these second marks.

Now one “big” change I made because we want a smooth scroll is that wherever there is “seekToTime”, I replaced it with seekToTime: toleranceBefore: kCMTimeZero toleranceAfter: kCMTimeZero.

If you need more information, please let me know! Thanks in advance!

+6
source share
2 answers

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

/* 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; } } 
+12
source

Along with bitmapdata.com's answer (using [AVPlayer setRate] instead of pause / seekTime) you need to have a video encoded with a key frame on each frame. Just transcoded my video with this setting, and now I can navigate my video very smoothly!

+3
source

Source: https://habr.com/ru/post/898683/


All Articles