我有一个简单的基于AVPlayer的OS应用程序,可以播放本地媒体。它具有基于-seekToTime:的跳过向前和向后的特性。在一些媒体上,让媒体继续播放(尤其是向前看)有一个恼人的3-7秒的延迟。我试过-寻找时间:公差之前:公差之后:,有可变的公差。不走运。
发布于 2015-03-10 19:55:49
把以前解决的问题记录在案.我注意到,当播放暂停时,seekToTime:跳过很好。我立即(即几周后)意识到,在寻找之前停止播放,然后重新启动可能是有意义的。到目前为止,问题已经百分之百地解决了,而且非常迅速。对于那些试图进行平滑循环的人来说,可能有些用处(但我不知道如何触发指示循环结束的完成处理程序)。不知道它是否适用于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;
}
https://stackoverflow.com/questions/28972819
复制相似问题