Class Track<T extends Track<T>>

java.lang.Object
com.oorian.html.Element<T>
com.oorian.html.elements.Track<T>

public class Track<T extends Track<T>> extends Element<T>
Represents an HTML <track> element for specifying timed text tracks for media elements.

This class provides functionality to create track elements that specify external text track resources for <video> and <audio> elements. Track elements enable features like subtitles, captions, descriptions, chapters, and metadata for media content, improving accessibility and user experience. Multiple track elements can be used to provide translations in different languages or alternative text formats.

Features:

  • Specifies timed text tracks for video and audio elements
  • Supports subtitles, captions, descriptions, chapters, and metadata
  • Enables multi-language subtitle support
  • Provides accessibility through captions and descriptions
  • Allows designation of default track
  • Uses WebVTT (Web Video Text Tracks) format
  • Extends Element for standard HTML functionality

Usage:


 // Create video with subtitle tracks
 Video video = new Video();
 video.setSrc("movie.mp4");

 // English subtitles (default)
 Track enSubs = new Track();
 enSubs.setKind(TrackKind.SUBTITLES);
 enSubs.setSrc("subtitles-en.vtt");
 enSubs.setSrcLang("en");
 enSubs.setLabel("English");
 enSubs.setDefault(true);
 video.addElement(enSubs);

 // Spanish subtitles
 Track esSubs = new Track();
 esSubs.setKind(TrackKind.SUBTITLES);
 esSubs.setSrc("subtitles-es.vtt");
 esSubs.setSrcLang("es");
 esSubs.setLabel("Español");
 video.addElement(esSubs);

 // Audio descriptions for accessibility
 Track descriptions = new Track();
 descriptions.setKind(TrackKind.DESCRIPTIONS);
 descriptions.setSrc("descriptions.vtt");
 descriptions.setSrcLang("en");
 descriptions.setLabel("English Descriptions");
 video.addElement(descriptions);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Track

      public Track()
      Constructs a Track element.

      Creates a new <track> element with no attributes set. Track properties should be configured using the setter methods.

  • Method Details

    • setDefault

      public T setDefault(boolean flag)
      Sets whether this track should be enabled by default.

      Only one track element per media element should have this attribute set. If no track has the default attribute, the browser will not display any text track by default.

      Parameters:
      flag - true to make this the default track, false otherwise
      Returns:
      this element for method chaining
    • setKind

      public T setKind(TrackKind kind)
      Sets the text track kind using the TrackKind enum.
      Parameters:
      kind - The kind of text track.
      Returns:
      This element for method chaining.
    • setKind

      public T setKind(String kind)
      Sets the kind of text track (subtitles, captions, descriptions, chapters, metadata).
      Parameters:
      kind - The kind of text track.
      Returns:
      This element for method chaining.
    • setLabel

      public T setLabel(String text)
      Sets the user-readable title for this text track.

      The label is displayed in the track selection interface to help the user choose the appropriate track.

      Parameters:
      text - The label text for this track.
      Returns:
      This element for method chaining.
    • setSrc

      public T setSrc(String url)
      Sets the URL of the track file.

      Specifies the location of the WebVTT (.vtt) file containing the timed text track data. This is a required attribute for track elements.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      url - the URL of the track file (typically a .vtt file)
    • setSrcLang

      public T setSrcLang(String languageCode)
      Sets the language of the track text data.

      This attribute is required when the track kind is "subtitles". The value must be a valid BCP 47 language tag (e.g., "en", "es").

      Parameters:
      languageCode - the BCP 47 language tag for the track
      Returns:
      this element for method chaining