AVPlayer seekToTime无法正常工作 [英] AVPlayer seekToTime not working properly

查看:217
本文介绍了AVPlayer seekToTime无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AVPlayer.seekToTime进行搜索时遇到问题,我想在以下的scrollViewDidScroll方法中寻找时间索引:

Im having a problem with seeking with AVPlayer.seekToTime, I have the time index that I want to seek to inside a scrollViewDidScroll method like this:

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秒,并让代表玩家时间索引的图像移动.这可能吗?我究竟做错了什么?请帮忙!

But the video does not flow nice. For example, when you scroll I want the video to only to move forward like 0.01 of a second (the video I have is real short only about 2.0 sec long) but when you scroll far enough, instead the video moves forward almost a whole second. Its really choppy and I'm not sure why I can't seek to like say 1.00 seconds to 1.01 seconds and have the image representing the time index on the player move. Is this possible? What am I doing wrong? Please help!

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

PS: I never call self.playerController.player?.play() if this helps

推荐答案

也许您之前的容忍度设置不正确.尝试以下操作:

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

代替您的代码:

  let offsetTime = scrollView.contentOffset.y * 0.1
  let seekTime : CMTime = CMTimeMake(Double(offsetTime), 1000)
self.playerController.player?.seekToTime(seekTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)

  • 时间刻度告诉您每秒有多少个单位
  • 此外,leranceBefore也应为kCMTimeZero
  • 希望这会有所帮助:-)

    hope this Helps :-)

    这篇关于AVPlayer seekToTime无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆