macos - AVPlayer seeToTime 旋转披萨

标签 macos performance avplayer seektotime

我有一个简单的基于 AVPlayer 的 OS X 应用程序,可以播放本地媒体。它具有基于 -seekToTime: 的向前和向后跳跃功能。在某些媒体上,让媒体继续播放(尤其是向前播放)会出现令人烦恼的 3-7 秒延迟。我尝试过 -eekToTime:toleranceBefore:toleranceAfter: ,具有可变的公差。运气不好。

最佳答案

发布之前已解决的问题记录...我注意到,当播放暂停时,seekToTime: 跳过工作正常。我立即(即几周后)意识到在搜索之前停止播放然后重新启动可能是有意义的。到目前为止,问题已经100%解决,而且进展速度非常快。对于尝试平滑循环的人来说可能有一些用处(但我不知道如何触发完成处理程序来表示循环结束)。不知道iOS 是否可以使用。附示例代码:

-(void) movePlayheadToASpecificTime
{
    // assumes this is a method for an AVPlayerView subclass, properly wired with IB
    // self.player is a property of AVPlayerView, which points to an AVPlayer

    // save the current rate
    float currentPlayingRate = self.player.rate;

    // may need fancier tweaking if the time scale changes within asset
    int32_t timeScale = self.player.currentItem.asset.duration.timescale;

    // stop playback
    self.player.rate = 0;

    Float64 desiredTimeInSeconds = 4.5; // or whatever

    // convert desired time to CMTime
    CMTime target = CMTimeMakeWithSeconds(desiredTimeInSeconds, timeScale);

    // perform the move
    [self.player seekToTime:target];

    // restore playing rate
    self.player.rate = currentPlayingRate;

}

关于macos - AVPlayer seeToTime 旋转披萨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28972819/

相关文章:

macos - 有没有办法在 NSWindow 上获得 NSPanel “Non activating” 样式功能?

java - 正确的 Info.plist 设置以在特定 JVM 中启动 Java 应用程序

Python - 许多方法,但差异很小

ios - 在 iOS 13 上暂停时强制重绘 AVPlayerLayer

ios - 表格 View 在向下滚动的同时播放其他单元格中的视频

iOS 8 - 在关闭全屏 AVPlayerViewController 时将方向更改回纵向

macos - 如何从 PowerShell 脚本打开另一个 PowerShell 控制台

html - Mac 上浏览器之间的字体大小不一致

Mysql:合理预测添加列或索引的持续时间

performance - 嵌套与链式联合