3

how can I make AVPlayerLayer display the exact video's frame in method seekToTime.

Now [AVPlayer seekToTime:CMTimeMakeWithSeconds(CMTimeGetSeconds(A, B))], the AVPlayerLayer only displays the frame at every 1-second change for example 1.50-2.50-3.50. I want it to display frame at 4.45 second for example. Is it possible?

Tung Vo Duc
  • 503
  • 6
  • 16

1 Answers1

7

You can use [AVPlayer seekToTime: toleranceBefore: toleranceAfter:] to get random media access with higher precision.
To get the highest precision possible, pass kCMTimeZero as argument for both tolerances. Note that this might add noticeable delay during seeks.

Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112
  • There is no delay for forward video but backward. How do I prevent it? – Tung Vo Duc Feb 18 '14 at 15:54
  • 1
    You can't. The higher precision requires more compositing operations. The seekToTime: methods also provide variants that take a completion handler. You could use a completion handler based seek to make your app more responsive. Those methods also have the advantage that the previous seek request gets canceled. https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Chapters/Reference.html#//apple_ref/occ/instm/AVPlayer/seekToTime:toleranceBefore:toleranceAfter:completionHandler: – Thomas Zoechling Feb 18 '14 at 16:38
  • Yes !! Do you have any idea how Instagram and built in Photo app do the video rewind so smooth. – Tung Vo Duc Feb 19 '14 at 11:12
  • @TungVo did you ever figure it out? – Johanisma May 13 '15 at 17:50