Difference between revisions of "Prefetch"

From A-SMIL.org
Jump to: navigation, search
(Corrected first seq which cannot have end condition with repeatCount at the same time)
m
Line 51: Line 51:
 
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 <tt>begin</tt> as "0s").  
 
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 <tt>begin</tt> as "0s").  
  
The first sequence plays whatever waiting message the user wishes to display, until it is ended by the "<tt>endEvent</tt>" event sent as "<tt>__prefetchEnd</tt>" sequence finishes (from within the second sequence; 1 second after prefetch completes).
+
The first sequence plays whatever waiting message the user wishes to display, until it is ended by the "<tt>endEvent</tt>" event sent as "<tt>__prefetchEnd</tt>" sequence finishes (from within the second sequence; 1 second after prefetch completes). Note that there are two <seq> layers as SMIL does not allow an "end" condition to be specified with "repeatCount", which potentially results in ambiguity.
  
 
The second sequence contains all prefetch instructions having the last item being the empty sequence named "<tt>__prefetchEnd</tt>", whose <tt>endEvent</tt> stops the first sequence (ending the display of waiting messages).
 
The second sequence contains all prefetch instructions having the last item being the empty sequence named "<tt>__prefetchEnd</tt>", whose <tt>endEvent</tt> stops the first sequence (ending the display of waiting messages).

Revision as of 10:52, 19 October 2010

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 in the section below.

Prefetching a file seamlessly

  <par>
 
    <seq end="__prefetchEnd.endEvent">
      <seq repeatCount="indefinite">
        <!-- Play waiting prompt or media files that are already in the cache -->
        <video src="http://server/old1.mpg" />
        <video src="http://server/old2.mpg" />
        <video src="http://server/old3.mpg" />
      </seq>
    </seq>
 
    <seq>
      <!-- Load files while first loop plays -->
      <prefetch src="http://server/new1.mpg" />
      <prefetch src="http://server/new2.mpg" />
      <prefetch src="http://server/new3.mpg" />
 
      <!-- Special item that sends out the __prefetchEnd.endEvent event when it ends -->
      <seq id="__prefetchEnd" dur="1s"/> 
    </seq>
 
    <seq begin="__prefetchEnd.endEvent" repeatCount="indefinite">
      <!-- Play loaded files -->
      <video src="http://server/new1.mpg" />
      <video src="http://server/new2.mpg" />
      <video src="http://server/new3.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). Note that there are two <seq> layers as SMIL does not allow an "end" condition to be specified with "repeatCount", which potentially results in ambiguity.

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