gpt4 book ai didi

iphone - iOS AVPlayer seektotime 锁定在某些点

转载 作者:可可西里 更新时间:2023-11-01 03:37:58 25 4
gpt4 key购买 nike

我或多或少使用了这里的代码:AVPlayer Video SeekToTime但是,当我尝试滚动时,它似乎锁定到某些时间点(基本上是第二个时间标记上的每一帧),所以当我擦洗擦洗器时,它会在我手指所在的位置和最后一秒之间来回移动通过并且视频仅在那些第二个标记处发生变化。

现在我确实做了一个“大”改变,因为我们想要平滑滚动是在任何有“seekToTime”的地方,我用 seekToTime:toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero 替换它。

如果您需要更多信息,请告诉我!提前致谢!

最佳答案

引用下面的代码:这段代码是苹果示例代码的一部分

AVPlayerDemo

如果您尝试实现流式播放器,请引用下面的示例代码。

StitchedStreamPlayer

此外,一个完整的精确擦洗工具是使用下面的类似 slider 。因为伟大的视频播放器应该考虑用户体验。如您所知,运行默认视频应用程序。擦洗时,如果向下拖动 slider 必须进行微调。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com