Class Audio

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasText, Serializable

@Tag("audio") public class Audio extends HtmlContainer
Represents an HTML <audio> tag.

By default this class enables display of the audio controls.

See Also:
  • Constructor Details

    • Audio

      public Audio()
      Constructor.
  • Method Details

    • setAltText

      public void setAltText(String text)
      Configure alternate text.
      Parameters:
      text - alternate text or null for none
    • addSource

      public void addSource(URI uri)
      Add an audio source and attempt to automatically infer its MIME type based on the URI path suffix.
      Parameters:
      uri - audio source
      Throws:
      IllegalArgumentException - if uri is null
      IllegalArgumentException - if uri's MIME type cannot be inferred
    • addSource

      public void addSource(URI uri, String mimeType)
      Add an audio source with the specified URL and MIME type.
      Parameters:
      uri - audio source
      mimeType - audio MIME type
      Throws:
      IllegalArgumentException - if either parameter is null
    • addSource

      public void addSource(String uri, String mimeType)
      Add an audio source with the specified URL and MIME type.
      Parameters:
      uri - audio source
      mimeType - audio MIME type
      Throws:
      IllegalArgumentException - if either parameter is null
    • removeSources

      public void removeSources()
      Remove all audio sources.
    • setLoop

      public void setLoop(boolean loop)
      Configure whether the audio should loop.
      Parameters:
      loop - true to loop, false to play once
    • setMuted

      public void setMuted(boolean muted)
      Configure whether the audio be muted.
      Parameters:
      muted - true for muted, false for unmuted
    • setShowControls

      public void setShowControls(boolean controls)
      Configure whether audio controls should be visible.
      Parameters:
      controls - true for visible audio controls, otherwise false
    • setPreload

      public void setPreload(Audio.PreloadMode preload)
      Configure what data to pre-load.
      Parameters:
      preload - data pre-load setting, or null to remove this option
    • play

      public void play()
      Start playing the audio.
    • setAttribute

      protected void setAttribute(String name, Object value)
    • inferMimeType

      protected String inferMimeType(String filename)
      Attempt to automatically infer an audio MIME type based on a file name.
      Parameters:
      filename - audio file name
      Throws:
      IllegalArgumentException - if filename's MIME type cannot be inferred
      IllegalArgumentException - if filename is null