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");
 
The browser's playback controls are shown by default, and they are all of the element that is rendered. A sound that is only played by the application, and that the visitor should not see a player for, is the one case where hiding them with Media.setControlsVisible(boolean) is right.
Since:
25.4
See Also:
  • Constructor Details

    • Audio

      public Audio()
      Creates an audio player without any source. The browser's playback controls are shown.
    • Audio

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