Class Track


@Marshalled(typeName="track") public class Track extends HtmlElementVoid<Track>
DTO for an HTML <track> element.

The track element is used to specify timed text tracks for media elements (audio and video). It allows you to add subtitles, captions, descriptions, chapters, or metadata to media content, making it more accessible and user-friendly.

Examples:

// Subtitles track Track subtitles = track() .kind("subtitles") .src("/media/subtitles-en.vtt") .srclang("en") .label("English"); // Captions track (for deaf/hard of hearing) Track captions = track() .kind("captions") .src("/media/captions-en.vtt") .srclang("en") .label("English Captions") .default_(true); // Descriptions track (for audio descriptions) Track descriptions = track() .kind("descriptions") .src("/media/descriptions-en.vtt") .srclang("en") .label("English Descriptions"); // Chapters track Track chapters = track() .kind("chapters") .src("/media/chapters.vtt") .srclang("en") .label("Chapters"); // Video with multiple tracks Video video = video() .src("/media/movie.mp4") .controls(true) .children( track("/media/subtitles-en.vtt", "subtitles").srclang("en").label("English").default_(true), track("/media/subtitles-es.vtt", "subtitles").srclang("es").label("Español"), track("/media/subtitles-fr.vtt", "subtitles").srclang("fr").label("Français") );

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

  • Method Details

    • default_

      public Track default_(Object value)
      default attribute.

      Specifies that this track should be enabled by default if no other text track is more suitable. This is useful for providing fallback captions or subtitles.

      This attribute uses deminimized values:

      • false - Track is not enabled by default (default)
      • true - Track is enabled by default
      • Other values - Passed through as-is
      Parameters:
      value - Whether this track should be enabled by default. Can be null to unset the attribute.
      Returns:
      This object.
    • kind

      public Track kind(String value)
      kind attribute.

      Specifies the type of text track. This determines how the track is used by the media element.

      Possible values:

      • "subtitles" - Subtitles for the deaf and hard-of-hearing
      • "captions" - Captions for the deaf and hard-of-hearing
      • "descriptions" - Text descriptions of the video content
      • "chapters" - Chapter titles for navigation
      • "metadata" - Metadata for the media
      Parameters:
      value - The type of text track. Can be null to unset the attribute.
      Returns:
      This object.
    • label

      public Track label(String value)
      label attribute.

      Specifies a user-visible label for the text track. This label is displayed in the media player's track selection menu.

      The label should be descriptive and help users identify the track (e.g., "English Subtitles", "Spanish Captions").

      Parameters:
      value - The user-visible label for the text track. Can be null to unset the attribute.
      Returns:
      This object.
    • src

      public Track src(Object value)
      src attribute.

      Address of the resource.

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      value - The new value for this attribute. Typically a URL or String. Can be null, in which case the attribute is stored with a null value (not removed).
      Returns:
      This object.
    • srclang

      public Track srclang(String value)
      srclang attribute.

      Specifies the language of the text track. This helps browsers and media players determine which track to use based on the user's language preferences.

      The value should be a valid language code (e.g., "en", "es", "fr", "de").

      Parameters:
      value - The language code of the text track. Can be null to unset the attribute.
      Returns:
      This object.