How Does SMIL Max Attribute Limit Active Duration?
The max attribute in Synchronized Multimedia Integration
Language (SMIL) defines a hard upper bound on an element's active
duration, ensuring playback or animation terminates even if repetitions,
child timing, or unresolved endpoints would otherwise extend it. By
evaluating the element’s computed intermediate active duration against
the specified clock value, the SMIL timing model truncates execution
precisely at the max threshold without altering the
underlying simple duration.
Understanding the SMIL Timing Model
To understand how max operates, it is necessary to
distinguish between simple duration and active duration:
- Simple Duration (
dur): The time required to play an element or animation sequence once through from start to finish. - Active Duration: The total time an element remains
active, accounting for iteration counts (
repeatCount), repeat durations (repeatDur), and runtime timeline events.
When an element defines repeating cycles or variable content lengths,
the active duration often exceeds the simple duration. The
max attribute acts directly upon the final calculated
active duration rather than modifying individual playback cycles.
Mechanics of the Max Constraint
During timeline calculation, the SMIL timing engine computes an
intermediate active duration based on attributes such as
dur, repeatCount, repeatDur, and
end. The engine then applies max through the
following process:
- Evaluation: The engine calculates the nominal
active duration. For instance, an animation with
dur="2s"andrepeatCount="5"yields a nominal active duration of 10 seconds. - Comparison: If the nominal active duration is
greater than the value defined in
max(e.g.,max="5s"), the active duration is clamped to themaxvalue. - Truncation: Playback stops at the 5-second mark, cutting off mid-cycle during the third repetition.
- Non-interference with Shorter Durations: If the
nominal active duration is less than or equal to
max, the attribute has no effect on the timeline.
<!-- Plays for 4.5 seconds total despite repeatCount specifying 8 seconds -->
<animate
attributeName="opacity"
dur="2s"
repeatCount="4"
max="4.5s"
from="0"
to="1" />Interaction with Other Timing Attributes
The max attribute interacts systematically with other
SMIL timing properties:
Min and Max Boundaries
When both min and max are present,
min takes precedence if a conflict occurs where
min is specified as greater than max. In
standard scenarios, min guarantees a minimum run time,
while max guarantees a maximum run time, defining a strict
operational window.
End vs. Max
The end attribute specifies an explicit event- or
clock-based termination point relative to the container's timeline.
While end forces an element to stop when an external
trigger occurs, max defines an internal time cap relative
to the element's own active start point.
Media and Unbounded Streams
For continuous media or indefinite animations
(repeatCount="indefinite"), max provides a
deterministic safeguard to prevent resource starvation by guaranteeing
that the element releases its active state after a fixed duration.