AVPlayer seekToTime 旋转披萨
AVPlayer seekToTime spinning pizza
我有一个简单的基于 AVPlayer 的 OS X 应用程序可以播放本地媒体。它具有基于-seekToTime: 的向前和向后跳跃功能。在某些媒体上,在让媒体继续播放(尤其是向前播放)时会有令人讨厌的 3-7 秒延迟。我试过 - seekToTime:toleranceBefore:toleranceAfter: ,公差可变。运气不好。
发布以前解决的问题以供记录...我注意到 seekToTime: skipping 在播放暂停时工作正常。我立即(即几周后)意识到在搜索之前停止播放然后重新启动可能是有意义的。至此,问题已经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;
}
我有一个简单的基于 AVPlayer 的 OS X 应用程序可以播放本地媒体。它具有基于-seekToTime: 的向前和向后跳跃功能。在某些媒体上,在让媒体继续播放(尤其是向前播放)时会有令人讨厌的 3-7 秒延迟。我试过 - seekToTime:toleranceBefore:toleranceAfter: ,公差可变。运气不好。
发布以前解决的问题以供记录...我注意到 seekToTime: skipping 在播放暂停时工作正常。我立即(即几周后)意识到在搜索之前停止播放然后重新启动可能是有意义的。至此,问题已经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;
}