【问题标题】:AVPlayer currentTime is negative valueAVPlayer currentTime 为负值
【发布时间】:2017-06-03 16:22:19
【问题描述】:

我正在使用 AVPlayer 播放音频文件。

但AVPlayer当前时间在开始时为负值。

当我使用seek(to: time) 方法移动特定时间时,AVPlayer 会在特定时间前大约0.1 秒播放。 (正好0.04~0.08)

有人知道这个问题吗?

【问题讨论】:

    标签: ios iphone avplayer


    【解决方案1】:

    您使用了错误的搜索方法。使用将容差定义为 0 的 seek 方法,因此它会准确搜索。

    Documentation for: seek(to:toleranceBefore:toleranceAfter:)

    这里有一些快速的示例代码,可以搜索到 100 秒:

    avPlayer.seek(to: someCMTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)
    

    【讨论】:

    • 不..现在是答案。它移动了 100 但又开始了 99.92~ 我猜它会导致 mp3 帧。
    • 确保在您正在制作的 CMTime 中使用当前时间刻度(来自您的资产)... int32_t timeScale = self.player.currentItem.asset.duration.timescale; CMTime 时间 = CMTimeMakeWithSeconds(77.000000, timeScale);
    • 我的代码是 self.seek(to: CMTime(seconds: to, preferredTimescale: self.currentTime().timescale)) 我移动了 1.2 秒但在 1.116897993 播放
    • 尝试使用玩家当前物品资产的时间刻度。所以像 self.seek(to: CMTime(seconds: to, preferredTimescale: avPlayer.currentItem.asset.duration.timescale)))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多