6

我在使用 AVPlayer.seekToTime 搜索时遇到问题,我有想要在这样的 scrollViewDidScroll 方法中搜索的时间索引:

func scrollViewDidScroll(scrollView: UIScrollView) {
    let offsetTime = scrollView.contentOffset.y * 0.1

    self.playerController.player?.seekToTime(CMTime(seconds: Double(offsetTime), preferredTimescale: 10), toleranceBefore: kCMTimePositiveInfinity, toleranceAfter: kCMTimeZero)

}

但是视频并不流畅。例如,当您滚动时,我希望视频仅向前移动 0.01 秒(我拥有的视频非常短,只有大约 2.0 秒长),但是当您滚动得足够远时,视频却向前移动了近一秒. 它真的很不稳定,我不知道为什么我不能尝试说 1.00 秒到 1.01 秒,并让图像代表玩家移动的时间索引。这可能吗?我究竟做错了什么?请帮忙!

PS:如果这有帮助,我从不调用 self.playerController.player?.play()

4

2 回答 2

18

也许你之前的容忍度没有设置好。尝试以下:

而不是你的代码:

  let offsetTime = scrollView.contentOffset.y * 0.1
  let seekTime : CMTime = CMTimeMake(Double(offsetTime), 1000)
self.playerController.player?.seekToTime(seekTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)
  • 时间刻度告诉你每秒有多少单位
  • 此外,toleranceBefore 也应该是 kCMTimeZero

希望这可以帮助 :-)

于 2016-04-12T15:13:12.410 回答
1

Hey I tried the above code in a Xamarin project using Octane.Xam.Videoplayer: https://components.xamarin.com/view/video-player

It worked really well!

Here is my sample code which I put into a Custom Renderer that inherited from VideoPlayerRenderer which can be found in the namespace Octane.Xam.VideoPlayer.iOS.Renderers:

public void CustomSeek(int seekTime)
    {
        CMTime tm = new CMTime(seekTime, 10000);
        if(NativeVideoPlayer.Player != null)
            NativeVideoPlayer.Player.Seek(tm, CMTime.Zero, CMTime.Zero);
    }

Keep in mind that you will have to use Version 1.1.4 of the Octane.Xam.VideoPlayer to gain access to the NativeVideoPlayer property of the VideoPlayerRenderer. In the future this property may be renamed to PlayerControl.

于 2016-09-09T16:21:17.957 回答