iphone - iOS AVPlayer seektotime 锁定在某些点

标签 iphone objective-c ios ipad avplayer

我或多或少使用了这里的代码: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/

相关文章:

iphone - 如何获取用户输入时 UITextField 中显示的实际字符串?

ios - 如何知道 UIVIewController 是否显示为 Peek Preview Controller

iphone - UIWebView execCommand 剪切、复制、粘贴

ios - Mapkit 如何在特定位置放置图钉?

ios - 核心数据: Illegal attempt to establish a relationship 'statusmedia' between objects in different contexts

iphone - CLLocationManager距离位置: returns -1

ios - Swift:功能完成的顺序是不可预测的

ios - 合并两个数组的每个元素并附加到一个数组

ios - 自动布局在第一次启动时隐藏图像

objective-c - NSTask/NSPipe 从 Unix 命令读取