MDN self-hosted library · e01.org

AudioSession: type property

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

js
// Set the audio session type for music playback
navigator.audioSession.type = "playback";

// Play music
audioElement.play();
js
// Set up for video conferencing (both playback and recording)
navigator.audioSession.type = "play-and-record";

// Start video call
const stream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true,
});
localVideo.srcObject = stream;
js
// Set transient type for a notification sound
navigator.audioSession.type = "transient";

// Play notification
notificationSound.play();