Conditional play

Jump to: navigation, search

SMIL features the "expr" tag for defining conditions during which a media item is played. This is can be applied to

  • Limiting the "validity period" within which a media file is licensed to play
  • Defining items that only play on certain days of the week
  • Allowing micro adjustment to playlists based on player ID/meta-data

The general format to specifying a conditional play is by adding the "expr" tag to a media item, such as

<seq repeatCount="indefinite">
      <video src="everyday.mpg" />
      <video src="mondays.mpg" expr="1=adapi-weekday()" />
   <seq dur="0.1" />

Only when the expression provided evaluates to "true" is the associated media item played.

In the sample code, item "everyday.mpg" is played every day the player is on, while item "mondays.mpg" is only played on Mondays.

Note that conditional play may break player optimizations designed to preload media objects for reducing gaps between items. We also suggest that add an brief idle sequential playlist in the end of the playlist to prevent from the player runs into idle status.

Supported Functions

The content of the expr tag is an HTML-encoded XPath expression. XPath functions are generally available, in addition to these following player-specific run-time conditional functions:

Function name Description Example (Shown with HTML-encoding)
smil-playerId() Returns player UUID in lower case. This is a fixed value that cannot be changed. expr="adapi-compare(smil-playerId(),'f1835d9f-be8f-4054-9e6c-123456789012')"
smil-playerName() Returns player name, which can be configured per player. expr="adapi-compare(smil-playerName(),'Entrance')"
adapi-date() Returns player's local date-time in ISO8601 format. expr="adapi-compare(adapi-date(),'2010-01-01T00:00:00')&lt;0"
adapi-gmdate() Returns player's UTC date-time in ISO8601 format (ending in UTC indicator "Z"). expr="adapi-compare(adapi-gmdate(),'2010-01-01T00:00:00Z')&lt;0"
adapi-weekday() Returns a number from 0 (Sunday) to 6 (Saturday) indicating player's local day-of-week. expr="adapi-weekday()=1"
adapi-gmweekday() Returns a number from 0 (Sunday) to 6 (Saturday) indicating player's UTC day-of-week. expr="adapi-gmweekday()=1"
adapi-compare(string comp1, string comp2) Returns -1 if comp1 is "less" than comp2 as a string, 0 if equal, 1 if "greater". expr="adapi-compare(adapi-date(),'2010-01-01T00:00:00')&lt;0"


From 9am to 17pm

expr="adapi-compare('09:00:00', substring-after(adapi-date(), 'T')) &lt;= 0 and 
adapi-compare('17:00:00', substring-after(adapi-date(), 'T')) &gt; 0"

From 2013/4/20 to 2013/9/17

expr="adapi-compare('2013-04-20T00:00:00', adapi-date()) &lt;= 0 and 
adapi-compare('2013-09-17T23:59:59', adapi-date()) &gt; 0"

Everyday between 9am to 17pm, from 2013/5/1 to 2013/6/15

expr="adapi-compare('2013-05-01T00:00:00', adapi-date()) &lt;= 0 and
adapi-compare('2013-06-15T23:59:59', adapi-date()) &gt; 0 and 
adapi-compare('09:00:00', substring-after(adapi-date(), 'T')) &lt;= 0 and adapi-compare('17:00:00', substring-after(adapi-date(), 'T')) &gt; 0"