LoginSignup
4
3

More than 3 years have passed since last update.

【Swift4】AVPlayerのseek()で時間がずれる件

Posted at

swiftの動画再生での話。

AVPlayer().seek(to time: CMTime)

でシークした後に動画再生を行うと、指定した時刻よりも最大0.5秒程度ずれた位置から再生が始まってしまい、なぜかと悩んでいた。

ドキュメント
https://developer.apple.com/documentation/avfoundation/avplayer/1385953-seek)
を見たらすぐに解決しました。

Discussion
The time to which the player is seeked may differ from the specified time for efficiency. For sample accurate seeking see seek(to:toleranceBefore:toleranceAfter:).

なるほど、正確な時刻にシークするためには、

AVPlayer().seek(to time: CMTime, 
toleranceBefore: CMTime, 
toleranceAfter: CMTime)

を使って、前後の誤差を小さく設定する必要があるとな。

ドキュメント読むのは大事ですね。

つまりデフォルトでは、-1〜1秒程度の誤差が許される設定になっているらしい。

おしまい。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3