Difference between revisions of "Prefetch"

From A-SMIL.org
Jump to: navigation, search
m
(Enriched sample code)
Line 13: Line 13:
 
</source>
 
</source>
  
Usually it is used while media is played in foreground. See sample code below.
+
Usually it is used while media is played in foreground. See sample code in the section below.
  
 
== Prefetching a file seamlessly ==
 
== Prefetching a file seamlessly ==
Line 22: Line 22:
 
     <seq end="__prefetchEnd.endEvent" repeatCount="indefinite">
 
     <seq end="__prefetchEnd.endEvent" repeatCount="indefinite">
 
       <!-- Play waiting prompt or media files that are already in the cache -->
 
       <!-- 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>
 
     <seq>
       <prefetch src="http://server/movie.mpg" />
+
      <!-- Load files while first loop plays -->
       <seq id="__prefetchEnd" dur="1s"/>
+
       <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>
  
 
     <seq begin="__prefetchEnd.endEvent" repeatCount="indefinite">
 
     <seq begin="__prefetchEnd.endEvent" repeatCount="indefinite">
       <video src="http://server/movie.mpg" />
+
      <!-- Play loaded files -->
 +
       <video src="http://server/new1.mpg" />
 +
      <video src="http://server/new2.mpg" />
 +
      <video src="http://server/new3.mpg" />
 
     </seq>
 
     </seq>
  

Revision as of 05:12, 22 December 2009

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" 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>
      <!-- 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).

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