files/en-us/web/api/audiosession/index.md
{{APIRef("Audio Session API")}}{{SeeCompatTable}}
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.
{{InheritanceDiagram}}
"auto", "playback", "transient", "transient-solo", "ambient", and "play-and-record".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 media
remoteVideo.srcObject = remoteMediaStream;
remoteVideo.play();
// Start capturing local media
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true,
});
localVideo.srcObject = stream;
{{Specifications}}
{{Compat}}