2

ローカル メディアを再生するシンプルな AVPlayer ベースの OS X アプリがあります。-seekToTime: に基づいて、前後にスキップする機能があります。一部のメディアでは、メディアの再生を継続するのに 3 ~ 7 秒の遅延が発生します (特に進行中)。私は試しました- seekToTime:toleranceBefore:toleranceAfter: 、可変許容値で。運がない。

4

1 に答える 1

2

以前に投稿すると、レコードの問題が解決されました... 再生が一時停止されたときに 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;

}
于 2015-03-10T19:55:49.410 に答える