AudioSession

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The AudioSession interface of the Audio Session API allows developers to specify how audio from a web application interacts with other audio playing on a device.

An audio session represents the aggregated audio output from a web page. It allows web pages to express the general nature of their audio output, such as playback, recording, or transient sounds like notifications. The platform can then use this information to determine how web-based audio should interact with other applications on the device, for example, whether web audio should pause other audio or play alongside it.

EventTarget AudioSession

Instance properties

AudioSession.type Experimental

A string representing the type of the audio session. Possible values include "auto", "playback", "transient", "transient-solo", "ambient", and "play-and-record".

Examples

Setting the audio session type for a video conferencing app

The following example sets the audio session type to "play-and-record" for a video conferencing application. On supporting platforms, this signals that the page needs simultaneous playback and recording, which may cause the system to route audio through the correct output (for example, earpiece instead of speaker on mobile devices) and prevent other applications' audio from interrupting the call.

js
navigator.audioSession.type = "play-and-record";

// Start playing remote media
remoteVideo.srcObject = remoteMediaStream;
remoteVideo.play();

// Start capturing local media
const stream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true,
});
localVideo.srcObject = stream;

Specifications

Specification
Audio Session
# audiosession

Browser compatibility

See also