MDN self-hosted library · e01.org
HTMLAudioElement / notebook

HTMLAudioElement

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const audioElement = new Audio("car_horn.wav");
js
audioElement.play();
js
const audioElement = new Audio("car_horn.wav");
audioElement.addEventListener("loadeddata", () => {
  let duration = audioElement.duration;
  // The duration variable now holds the duration (in seconds) of the audio clip
});