Prefetch

From A-SMIL.org
Revision as of 15:41, 29 September 2009 by SMIL T.A. (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Media files used in SMIL are loaded "on-the-fly" as they are used for the first time. After they are played once, they are kept in the cache storage. Unless storage runs out, media files are played from the cache storage when they are played subsequently.

The downside of this mechanism is that when large media files are used for the first time (e.g., movies), there is a visible gap waiting for the first download to complete. The player seems "frozen" while waiting for download to complete.

A mechanism exists in SMIL to "pre-load" the cache with a file that will be needed later on in advance, in a controlled fashion. This makes use of the SMIL "prefetch" tag.

Prefetching a file

The following SMIL code segment loads "movie.mpg" into the cache without playing it.

  <prefetch src="http://server/movie.mpg" />

Usually it is used while media is played in foreground. See sample code below.

  <par>
 
    <seq end="__prefetchEnd.endEvent" repeatCount="indefinite">
      <!-- Play waiting prompt or media files that are already in the cache -->
    </seq>
 
    <seq>
      <prefetch src="http://server/movie.mpg" />
      <seq id="__prefetchEnd" dur="1s"/>
    </seq>
 
    <seq begin="__prefetchEnd.endEvent" repeatCount="indefinite">
      <video src="http://server/movie.mpg" />
    </seq>
 
  </par>

This example uses several SMIL techniques. 3 sequences are run inside a parallel time container. The first two sequences begin immediately (using default value of begin as "0s").

The first sequence plays whatever waiting message the user wishes to display, until it is ended by the "endEvent" event sent as "__prefetchEnd" sequence finishes (from within the second sequence; 1 second after prefetch completes).

The second sequence contains all prefetch instructions having the last item being the empty sequence named "__prefetchEnd", whose endEvent stops the first sequence (ending the display of waiting messages).

The third sequence starts by the same event that ends the first sequence, and plays media files downloaded by the prefetch sequence.

Related