我或多或少使用这里的代码:AVPlayer Video SeekToTime
但是,当我尝试滚动时,似乎锁定到了某些时间点(基本上是每帧位于第二个时间标记上),因此当我通过滑动器进行擦洗时,会不断在手指所在的位置和最后一秒钟之间来回射击。通过,并且视频仅在第二秒标记处更改。
现在,我做了一个“大”更改,因为我们想要平滑滚动,是在任何存在“seekToTime”的地方,我都将其替换为seekToTime:toleranceBefore:kCMTimeZeroleranceAfter:kCMTimeZero。
如果您需要更多信息,请告诉我!提前致谢!
最佳答案
请参阅以下代码:此代码是Apple示例代码的一部分
AVPlayerDemo
如果您尝试实现流播放器,请引用下面的示例代码。
StitchedStreamPlayer
另外,要完全擦洗的完整工具是使用下面的类似滑块。
因为出色的Video Player应该考虑使用UX。如您所知,运行默认的Video App。进行擦洗时,如果向下拖动滑块,则必须进行微调。
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;
}
}
关于iphone - iOS AVPlayer seektotime锁定在某些点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7663994/