AVPlayer seekToTime not working properly

。_饼干妹妹 提交于 2019-12-05 18:05:29

Maybe your tolerance before is not set right. try the Following:

instead of your code:

  let offsetTime = scrollView.contentOffset.y * 0.1
  let seekTime : CMTime = CMTimeMake(Double(offsetTime), 1000)
self.playerController.player?.seekToTime(seekTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)
  • the Time Scale tells how many units you have per second
  • Also, toleranceBefore should ALSO be kCMTimeZero

hope this Helps :-)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!