我有一个简单的基于 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/