Class Audio


@Marshalled(typeName="audio") public class Audio extends HtmlElementMixed<Audio>
DTO for an HTML <audio> element.

The audio element embeds sound content in documents. It can contain audio streams, audio files, or other audio sources. The browser will choose the most appropriate source based on format support and user preferences.

Examples:

// Simple audio with single source Audio audio1 = audio().src("audio.mp3").controls(true); // Audio with multiple sources for browser compatibility Audio audio2 = audio().controls(true) .children( source().src("audio.mp3").type("audio/mpeg"), source().src("audio.ogg").type("audio/ogg") ); // Autoplay audio with loop Audio audio3 = audio().src("background.mp3").autoplay(true).loop(true).muted(true);

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

See Also:
  • Constructor Details

    • Audio

      public Audio()
      Creates an empty Audio element.
    • Audio

      public Audio(String src)
      Creates an Audio element with the specified src(Object) attribute.
      Parameters:
      src - The src(Object) attribute. Can be null, in which case the attribute is stored with a null value (not removed).
  • Method Details

    • autoplay

      public Audio autoplay(Object value)
      autoplay attribute.

      Hint that the media resource can be started automatically when the page is loaded.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "autoplay"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • controls

      public Audio controls(Object value)
      controls attribute.

      Show user agent controls.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "controls"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • crossorigin

      public Audio crossorigin(String value)
      crossorigin attribute.

      Specifies how the element handles cross-origin requests for CORS (Cross-Origin Resource Sharing).

      Possible values:

      • "anonymous" - Cross-origin requests are made without credentials
      • "use-credentials" - Cross-origin requests include credentials
      Parameters:
      value - How to handle cross-origin requests. Can be null to unset the attribute.
      Returns:
      This object.
    • loop

      public Audio loop(Object value)
      loop attribute.

      Causes the media to automatically restart from the beginning when it reaches the end.

      Parameters:
      value - If true, the media will loop continuously. Can be null to unset the attribute.
      Returns:
      This object.
    • mediagroup

      public Audio mediagroup(String value)
      mediagroup attribute.

      Groups multiple media elements together so they can be controlled as a single unit. All media elements with the same mediagroup value will share the same MediaController, allowing synchronized playback.

      This is useful for creating synchronized audio/video presentations or multiple audio tracks.

      Parameters:
      value - The name of the media group to join. Can be null to unset the attribute.
      Returns:
      This object.
    • muted

      public Audio muted(Object value)
      muted attribute.

      Mutes the audio output by default. Useful for autoplay videos where audio should be disabled initially.

      Parameters:
      value - If true, the media will be muted by default. Can be null to unset the attribute.
      Returns:
      This object.
    • preload

      public Audio preload(Object value)
      preload attribute.

      Specifies how the browser should load the media resource.

      Possible values:

      • "none" - Do not preload the media
      • "metadata" - Preload only metadata (duration, dimensions, etc.)
      • "auto" - Preload the entire media file (default)
      Parameters:
      value - How much of the media to preload. Can be null to unset the attribute.
      Returns:
      This object.
    • src

      public Audio 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.