How Does SMIL Reference External Files?
In Synchronized Multimedia Integration Language (SMIL), the
<text> element references external text files by
using the src attribute to point directly to the file's
Uniform Resource Identifier (URI). This mechanism allows multimedia
presentations to decouple textual content—such as subtitles, captions,
and sidebars—from presentation logic, rendering plain text, HTML, or
SMIL-Text files within designated spatial regions and synchronizing them
with audio and video timelines.
The Role of the src
Attribute
The <text> tag operates as a media object element
in SMIL, functioning similarly to <audio>,
<video>, or <img>. To pull in
content from an external source, you assign the relative or absolute
path of the target document to the src attribute.
<smil xmlns="http://www.w3.org/ns/SMIL" version="3.0">
<head>
<layout>
<root-layout width="640" height="480" backgroundColor="black" />
<region id="captionArea" top="400" left="20" width="600" height="60" />
</layout>
</head>
<body>
<par>
<video src="presentation.mp4" />
<text src="transcript.txt" region="captionArea" begin="0s" dur="30s" />
</par>
</body>
</smil>When the presentation engine encounters the <text>
element, it initiates a network or file system fetch for the URI defined
in src (transcript.txt in the example above)
and prepares it for rendering at the designated start time.
Declaring MIME
Types with the type Attribute
External text documents can come in multiple formats, ranging from
simple ASCII files to rich markup documents. While many SMIL user agents
can infer the file type from file extensions or HTTP headers, best
practice dictates defining the MIME type explicitly using the
type attribute.
- Plain Text:
<text src="subtitles.txt" type="text/plain" />renders unformatted text using system default typography. - HTML Content:
<text src="overview.html" type="text/html" />allows the media engine to render rich text containing styling, headings, and links inside the target viewport. - SMIL-Text:
<text src="captions.smiltext" type="text/smiltext" />references formatted SMIL-Text documents containing dynamic text flow and styling instructions.
Explicitly declaring the MIME type ensures that the SMIL player loads the correct rendering engine and fails gracefully if an unsupported text format is encountered.
Spatial Mapping and Synchronization
Referencing an external text file requires spatial and temporal coordination with the rest of the presentation:
- Spatial Placement: The
regionattribute maps the referenced external text to an abstract coordinate box defined inside the<layout>section of the SMIL document. - Timeline Synchronization: Standard SMIL timing
attributes—such as
begin,dur, andend—govern when the referenced text file appears and how long it remains visible. - Sequential Display: Placing multiple
<text>elements inside a<seq>container allows different external text files to display consecutively across successive intervals.
<text> vs.
<textstream>
For static external files that load entirely before or at the moment
of display, <text> with a standard src
reference is the standard approach. For continuous, time-coded subtitle
feeds or real-time streaming transcripts (such as RTP or WebVTT
streams), SMIL provides the alternative <textstream>
element, which uses its src attribute to connect to dynamic
streaming protocols rather than static document endpoints.