Class Audio

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasAriaLabel, HasComponents, HasComponentsOfType<Component>, HasElement, HasEnabled, HasSize, HasStyle, Serializable

@NullMarked @Tag("audio") public class Audio extends Media
Component representing an <audio> element — the browser's built-in audio player.

List the recording in as many formats as you want to support, one Source each, and the browser plays the first one it can decode:

 Audio audio = new Audio();
 audio.addSource("/chime.ogg", "audio/ogg");
 audio.addSource("/chime.mp3", "audio/mpeg");
 audio.setControlsVisible(true);
 
Nothing of the element is rendered until Media.setControlsVisible(boolean) is called, so a player that the visitor is meant to start needs that call. A sound that is only played by the application, and that the visitor should not see a player for, is the one case where leaving the controls off is right.
See Also:
  • Constructor Details

    • Audio

      public Audio()
      Creates an audio player without any source.
    • Audio

      public Audio(Source... sources)
      Creates an audio player that plays the first of the given sources the browser can decode.
      Parameters:
      sources - the same recording in one or more file formats