How Does repeatCount Repeat Elements in SMIL?

The repeatCount attribute in Synchronized Multimedia Integration Language (SMIL) defines the number of times a media element or temporal container plays its simple duration. By accepting numeric values, fractional counts, or the keyword indefinite, repeatCount allows authors to precisely control playback loops across standalone media files, animation elements, and complex timing containers such as <seq> and <par>.

Understanding the repeatCount Syntax and Values

The repeatCount attribute specifies the iteration count for the active duration of an element. It accepts two primary types of values:

Repeating Individual Media and Animation Elements

When applied to basic media elements (such as <video>, <audio>, or <img>) or SVG animation elements (such as <animate> or <animateTransform>), repeatCount determines how many times the media payload or animation track runs from start to finish.

<!-- Plays a 4-second audio clip 3 full times (Total active duration: 12 seconds) -->
<audio src="chime.mp3" dur="4s" repeatCount="3" />

<!-- Loops an SVG rotation animation continuously -->
<animateTransform attributeName="transform"
                  type="rotate"
                  from="0 50 50"
                  to="360 50 50"
                  dur="2s"
                  repeatCount="indefinite" />

For media elements with a natural intrinsic duration, defining repeatCount without an explicit dur will repeat the intrinsic timeline of the media file. If dur is explicitly defined, each iteration uses the defined dur rather than the media file's natural length.

Repeating Container Elements: <seq>, <par>, and <excl>

SMIL timing containers manage groups of elements, and applying repeatCount to a container repeats the entire group structure as a single cohesive unit:

<!-- Repeats the sequence of two slides twice (Total active duration: 20 seconds) -->
<seq repeatCount="2">
  <img src="slide1.jpg" dur="5s" />
  <img src="slide2.jpg" dur="5s" />
</seq>

At the start of each iteration, all child elements reset to their initial state, restarting any nested timelines or visual transformations.

Calculating Active Duration with repeatCount

The total active duration of an element with repeatCount is calculated using the formula:

\[\text{Active Duration} = \text{dur} \times \text{repeatCount}\]

If a 5-second video uses repeatCount="1.5", the element plays for a total of 7.5 seconds, cutting off midway through the second playback loop.

Interactions with Other SMIL Timing Attributes

SMIL provides additional timing controls that can modify or constrain how repeatCount behaves: