Conditional Play

SMIL features the expr attribute. We use this to define conditions for media playback. This is a powerful feature. Especially when you combine this with triggers.

A simple Example

The general format to specifying a conditional play is by adding the expr attribute to a media item. When the given expression equals to “true” the associated item is played.

<seq repeatCount="indefinite">
   <seq>
      <img src="everyday.jpg" />
      <img src="wednesday.jpg" expr="3=adapi-weekday()" />
   </seq>
   <seq dur="0.1" />
</seq>
Image wednesday.jpg will only be displayed on Wednesday

btw: This also works with playlist container.

Supported Functions

The expr tag content is an HTML-encoded XPath 1.0 expression or XPath 1.0 functions.

In addition to XPath 1.0, IAdea established some player-specific functions also date and compare functionally which were introduced in XPath 2.0. The prefix adapi- is used for this function-set.

Function Description Example
smil-playerId() Returns player UUID in lower case. expr="adapi-compare(smil-playerId(),'player-uuid')"
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"

Some more Examples

<par expr="adapi-weekday()=1 or adapi-weekday()=5">
	<seq repeatCount="indefinite">
		<video src="video.mp4"/>
		<img dur="3s" src="image.jpg" />
	</seq>
</par>
Play par tag on Sunday or Friday
<par expr="adapi-compare(adapi-date(), '2021-01-25T00:00:00')>0 and compare(adapi-date(), '2021-01-29T23:59:59')<=0">
	<seq repeatCount="indefinite">
		<video src="video.mp4"/>
		<img dur="3s" src="image.jpg" />
	</seq>
</par>
Play par tag between 25th of January and 29th of January

Even more sophisticated combinations are possible. ;-)

<ref expr="adapi-compare(substring-before(adapi-date(), 'T'), '2022-05-10')>=0 and
	adapi-compare(substring-before(adapi-date(), 'T'), '2022-05-25')<=0 and
	adapi-compare(substring-after(adapi-date(), 'T'), '08:00:00')>=0 and
	adapi-compare(substring-after(adapi-date(), 'T'), '12:00:00')<=0 and
	((1=adapi-weekday() and adapi-compare(substring-after(adapi-date(), 'T'), '15:00:00')>=0 and
	adapi-compare(substring-after(adapi-date(), 'T'), '20:00:00')<=0) or (3=adapi-weekday() and
	adapi-compare(substring-after(adapi-date(), 'T'), '15:00:00')>=0 and
	adapi-compare(substring-after(adapi-date(), 'T'), '20:00:00')<=0) or (5=adapi-weekday() and
	adapi-compare(substring-after(adapi-date(), 'T'), '15:00:00')>=0 and
	adapi-compare(substring-after(adapi-date(), 'T'), '20:00:00')<=0))"
	src="rss-widget.wgt" dur="10s" type="application/widget" >
Play rss-widget between 10th and 25th of May 2022 every day between 8:00 and 12:00 o clock and additional on Mondays, Wednesdays, and Fridays between 15:00 and 20:00 o'clock.

You can study a real-world example of conditional play here.