SMIL Tutorial
SMIL Tutorial
SMIL Introduction
SMIL is an HTML-like language for describing audiovisual presentations.
What Is SMIL?
• SMIL stands for Synchronized Multimedia Integration Language
• SMIL is pronounced "smile"
• SMIL is a language for describing audiovisual presentations
• SMIL is easy to learn and understand
• SMIL is an HTML-like language
• SMIL is written in XML
• SMIL presentations can be written using a text-editor
• SMIL is a W3C recommendation
From the example above you can see that SMIL is an HTML-like language that can be written using a
simple text-editor.
The <smil></smil> tags defines the SMIL document. A <body> element defines the body of the presentation.
A <seq> element defines a sequence to display. The repeatCount attribute defines an indefinite loop. Each
<img> element has a src attribute to define the image source and a dur attribute to define the duration of the
display.
W3C has been developing SMIL since 1997, as a language for choreographing multimedia presentations
where audio, video, text and graphics are combined in real-time.
1
SMIL became a W3C Recommendation 15. June 1998.
SMIL Files
A SMIL file describes a multimedia presentation.
SMIL Files
A SMIL file contains all the information necessary to describe a multimedia presentation.
SMIL files are stored with the file extension .smil
SMIL Markup
Since SMIL is based on XML, the tags are case sensitive. All SMIL tags requires lowercase letters.
A SMIL document must start with a <smil> tag and end with a </smil> closing tag. It may contain a <head>
element and must contain a <body> element.
The <head> element is used to store information about the presentation layout and other meta information.
SMIL in HTML
Internet Explorer can run SMIL presentations inside HTML files.
Running SMIL in IE
SMIL elements can be inserted into HTML files in Internet Explorer 5.5 or later.
• To use SMIL elements in your HTML pages, you must add a "time" namespace to recognize the
elements. To use SMIL attributes, you must define a "time" class. Here is how to do it:
• Add a time namespace to the <html> tag
• Add an <?import> element to import the "time" namespace
• Add a <style> element to define the class "time"
Example<html xmlns:time="urn:schemas-microsoft-com:time">
<head>
<?import namespace="time" implementation="#default#time2">
2
<style>.time {behavior: url(#default#time2)}</style>
</head>
You will see the full example in the next paragraph.
SMIL Example
To run a SMIL presentation in an HTML page, just add a prefix and a class attribute to the SMIL elements
Example
html xmlns:time="urn:schemas-microsoft-com:time">
<head>
<?import namespace="time" implementation="#default#time2">
<style>.time {behavior: url(#default#time2)}</style>
</head>
<body>
<time:seq repeatCount="indefinite">
<img class="time" src="image1.jpg" dur="3s" />
<img class="time" src="image2.jpg" dur="3s" />
</time:seq>
</body>
</html>
In the example above we have added class="time" to the <img> elements, and a "time" prefix to the SMIL
elements
The class and namespace do not have to be called "time". Any name will do.
XHTML+SMIL
Browsers will treat audio and video as easy as old browsers treat text and images.
HTML+TIME
In the previous chapter you saw Internet Explorer could display SMIL elements in HTML.
Why XHTML+SMIL?
Is it not obvious?
To run a SMIL presentation today, you'll need a SMIL player. Would it not be nicer if you could run SMIL
directly in your browser?
SMIL defines a set of multimedia elements. Each of these elements can be given layout, timing, and
transition attributes and rules. Would it not be nicer if you could add these attributes and rules to all your
HTML elements?
SMIL Timing
Timing is about when to begin and when to stop.
3
Timelines and Timing
Most SMIL element have timing attributes to define the timeline of the presentation.
Timing attributes defines the start time and the duration of an element.
The following table lists the possible time formats:
Format Examples
The value "indefinite" can also be used to define never ending loops.
Duration
The duration (dur="5s") attribute of an element defines how long the element will be visible:
Example
<html>
<head>
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<img class="t" src="image1.jpg" dur="5s" />
</body> </html>
When To Begin?
The begin (begin="2s") defines when the element will be visible (start playing):Example<html>
<head>
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<img class="t" src="image1.jpg" begin="2s" />
</body>
</html>
SMIL Sequence
seq - the most common SMIL element - defines a sequence.
4
dur time Sets the duration for the display
repeatCount number Sets the number of repetitions for
the display
SMIL in Parallel
Objects inside a par element will be played at the same time (in parallel).
Synchronization
A parallel group of clips can be stopped at the same time using the endsync attribute in the <par> tag.
endsync="first" stops all the clips in the <par> group when the shortest clip are finished regardless of any
time parameters set for the other clips.
endsync="last" concludes the <par> group when all clips have finished playing. This is the default.
endsync="id(ID)" concludes the <par> group when the clip with the identified (ID) clip are finished. The ID is
referring to the value of the clips id attribute.
Displaying Objects in ParallelExample<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
5
<par>
<t:audio src="liar.wav" repeatCount="indefinite" type="wav" />
<t:seq repeatCount="indefinite">
<h2 class="t" dur="1s">I will display for one second</h2>
<h2 class="t" dur="2s">I will display for two seconds</h2>
</t:seq>
</par>
</body>
</html>
SMIL Transitions
Transitions can generate effects like "fading" and "wiping" to elements.
Attributes
The <transitionfilter> tag can have several attributes. The most common are:
Attribute Description Example
type Defines the type of transition filter type="clockWipe"
(see transition filter list)
begin Defines when the transition begin="0s"
should begin
mode Defines the transition mode mode="in"
from Defines the starting value of the from="0.2"
transition
to Defines the ending value of the to="0.8"
transition
Transition Filters
The following transition filters can be used:fade, barnDoorWipe, barWipe, clockWipe, ellipseWipe, fanWipe,
irisWipe, pushWipe, slideWipe, snakeWipe, spiralWipe, starWipe
Displaying Transitions
In the example below the image will be displayed for 4 seconds. The transition filter will use 2 second to
"clockWipe" the image into its place.Example<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<t:transitionfilter targetelement="keyb" type="clockWipe"
begin="keyb.begin" dur="2s" />
<img id="keyb" class="t" src="pic_keyb.jpg" dur="4s"
width="128" height="107" />
</body>
</html>
Media Elements
The following media elements can be used to include media objects in a SMIL document:
Element Description Ver
<animation> Defines an animation 1
6
<audio> Defines an audio clip 1
<brush> Defines a brush 1
<img> Defines an image 1
<param> Defines a parameter 1
<ref> Defines a generic media reference 1
<text> Defines a text 1
<textstream> Defines a texstream 1
<video> Defines a video 1
Media Attributes
Each media object in a SMIL document must be included using a reference (URL) in the src attribute. The
src attribute is the most commonly used attribute for media elements.
The type attribute is used to define the media type. If the type attribute is omitted the application should rely
on the type information communicated by the server. Developers should not rely on the file type extension to
define the file type.
Attribute Description Ver
erase Defines the behavior of the element after any timing is 1
complete
src Defines the source of a media object 1
type Defines the media type 1
7
.Example
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
</head>
<body>
<t:video
src="http://www.ananova.com/about/vap_windows_check.wmv"
repeatCount="indefinite" type="wmv" />
</body>
</html>
SMIL Examples
How to Play a SMIL File?
To view a SMIL presentation, you will need a SMIL player installed on your computer.
Apple's Quicktime player, Windows Media Player, and RealNetworks RealPlayer support SMIL.
Microsoft's Internet Explorer has limited support for SMIL. The open-source Mozilla project is incorporating
SMIL, but the progress is slow.
Note: The examples below will use IE 5.5 or later to demonstrate SMIL.
SMIL Timing
• Specify how long an element should be visible
<html>
<head>
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
</body>
</html>
</body>
</html>
SMIL Sequences
• Displaying a sequence of images
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<t:seq repeatCount="indefinite">
<img class="t" src="pic_keyb.jpg" dur="1s"
8
width="128" height="107" />
<img class="t" src="pic_http.jpg" dur="1s"
width="128" height="102" />
</t:seq>
</body>
</html>
• Displaying a sequence of texts
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<t:seq repeatCount="indefinite">
<h2 class="t" dur="1s">
I will display for one second</h2>
<h2 class="t" dur="2s">
I will display for two seconds</h2>
<h2 class="t" dur="3s">
I will display for three seconds</h2>
</t:seq>
</body>
</html>
SMIL in Parallel
• Displaying things simultaneously
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<t:par>
<t:seq repeatCount="indefinite">
<h2 class="t" dur="1s">
I will display for one second</h2>
<h2 class="t" dur="2s">
I will display for two seconds</h2>
</t:seq>
<t:seq repeatCount="indefinite">
<img class="t" src="pic_keyb.jpg" dur="1s"
width="128" height="107" />
<img class="t" src="pic_http.jpg" dur="2s"
width="128" height="102" />
</t:seq>
</t:par>
</body>
</html>
SMIL Transitions
• Transition effect
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
9
<?import namespace="t" implementation="#default#time2">
<style>.t {behavior: url(#default#time2)}</style>
</head>
<body>
<t:transitionfilter targetelement="keyb"
type="clockWipe"
begin="keyb.begin"
dur="2s" />
</body>
</html>
SMIL Media
• SMIL audio
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
</head>
<body>
<t:audio
src="liar.wav"
repeatCount="indefinite"
type="wav" />
</body>
</html>
• SMIL video
<html xmlns:t="urn:schemas-microsoft-com:time">
<head>
<?import namespace="t" implementation="#default#time2">
</head>
<body>
<t:audio src="http://www.ananova.com/about/vap_windows_check.wmv"
repeatCount="indefinite"
type="wmv" />
</body>
</html>
SMIL Reference
This is a complete SMIL 2.0 Reference (under construction).
10
Attribute Description Ver
begin Sets the delay before the element is displayed 1
dur Sets the duration for the display 1
endsync Synchronizes the stopping of parallel elements 1
repeatCount Sets the number of repetitions for the display 1
By: DataIntegratedEntity
Source: http://w3schools.com/smil/default.asp
11