AVPlayer seekToTime旋转披萨

时间:2015-03-10 19:49:24

标签: macos performance avplayer seektotime

我有一个简单的基于AVPlayer的OS X应用程序,可播放本地媒体。它有一个跳过前进和后退功能,基于-seekToTime:。在某些媒体上,让媒体继续播放(特别是未来)会有3-7秒的烦恼。我试过 - seekToTime:toleranceBefore:toleranceAfter :,具有可变公差。没有运气。

1 个答案:

答案 0 :(得分: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;

}