我有一个简单的基于 AVPlayer 的 OS X 应用程序,可以播放本地媒体。它具有基于 -seekToTime: 的向前和向后跳过功能。在某些媒体上,让媒体继续播放(尤其是继续播放)会有 3-7 秒的延迟。我已经尝试过 - seekToTime:toleranceBefore:toleranceAfter: ,具有可变公差。没运气。
问问题
214 次
1 回答
2
发布以前解决的问题以供记录...我注意到 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;
}
于 2015-03-10T19:55:49.410 回答