【问题标题】:iOS AVPlayer seektotime locking at certain pointsiOS AVPlayer seektotime 锁定在某些点
【发布时间】:2011-10-05 15:43:28
【问题描述】:

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

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

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

【问题讨论】:

    标签: iphone objective-c ios ipad avplayer


    【解决方案1】:

    参考以下代码:此代码是 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;
        }
    }
    

    【讨论】:

    • 你知道这段代码在他们为我制作的视图/控制器之外工作得更好。不只是尝试洗涤器代码,效果更好,谢谢!
    【解决方案2】:

    除了 bitmapdata.com 答案(使用 [AVPlayer setRate] 而不是 pause/seekTime),您还需要在每帧上使用关键帧对视频进行编码。 只需使用该设置重新编码我的视频,现在我可以非常流畅地浏览我的视频!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多