Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) <code>AVPlayer</code> will buffer the video in several cases, none cleary documented. I'd say you can expect buffering when you init the video, and when you replace the current item. You can observe <code>currentItem.loadedTimeRanges</code> to know what's going on. That property will tell you which video time ranges has been loaded.</p> <p>Also, there is a few other <code>currentItem</code> properties that may help you: <code>playbackLikelyToKeepUp</code>, <code>playbackBufferFull</code> and <code>playbackBufferEmpty</code>.</p> <p>Achieving a perfect gapless playback is not easy.</p> <pre><code>/* player is an instance of AVPlayer */ [player addObserver:self forKeyPath:@"currentItem.loadedTimeRanges" options:NSKeyValueObservingOptionNew context:kTimeRangesKVO]; </code></pre> <p>In <code>observeValueForKeyPath:ofObject:change:context:</code>:</p> <pre><code>if (kTimeRangesKVO == context) { NSArray *timeRanges = (NSArray *)[change objectForKey:NSKeyValueChangeNewKey]; if (timeRanges &amp;&amp; [timeRanges count]) { CMTimeRange timerange = [[timeRanges objectAtIndex:0] CMTimeRangeValue]; NSLog(@" . . . %.5f -&gt; %.5f", CMTimeGetSeconds(timerange.start), CMTimeGetSeconds(CMTimeAdd(timerange.start, timerange.duration))); } } </code></pre> <p>2) Just keep an eye on <code>player.rate</code>.</p> <pre><code>[player addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:kRateDidChangeKVO]; </code></pre> <p>Then in your <code>observeValueForKeyPath:ofObject:change:context:</code>:</p> <pre><code> if (kRateDidChangeKVO == context) { NSLog(@"Player playback rate changed: %.5f", player.rate); if (player.rate == 0.0) { NSLog(@" . . . PAUSED (or just started)"); } } </code></pre> <p>3) You can <a href="https://stackoverflow.com/search?q=movie%20images%20avfoundation%20answers:1%20isquestion:1&amp;submit=search">build a movie of a given length using a still image</a> but it's easier to use a regular <code>UIImageView</code> on top of the player. Hide/show it when needed. </p> <p><strong>Sample project</strong>: feel free to play with <a href="https://github.com/djromero/AVFoundationQuestions/tree/10648963" rel="nofollow noreferrer">the code I wrote to support my answer</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload