AudioSession
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheAudioSession interface of theAudio 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.
In this article
Instance properties
AudioSession.typeExperimentalA 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.
navigator.audioSession.type = "play-and-record";// Start playing remote mediaremoteVideo.srcObject = remoteMediaStream;remoteVideo.play();// Start capturing local mediaconst stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true,});localVideo.srcObject = stream;Specifications
| Specification |
|---|
| Audio Session> # audiosession> |