iOS AVPlayer在某些点上进行seektotime锁定

Mat*_*ark 6 iphone objective-c ipad ios avplayer

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

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

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

bit*_*com 12

请参考下面的代码:此代码是Apple示例代码的一部分

AVPlayerDemo

如果您尝试实现流媒体播放器,请参阅下面的示例代码.

StitchedStreamPlayer

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

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;
    }
}
Run Code Online (Sandbox Code Playgroud)