大网数据广告活动
Web 标准与前端开发

AudioSession: type property

· 52CE 我爱测

The **`type`** property of the AudioSession interface represents the type of the audio session.

Audio Session API

The type property of the AudioSession interface represents the type of the audio session.

The audio session type describes the general nature of a web page's audio output, allowing the platform to determine how web-based audio should interact with other audio playing on the device.

Value

A string representing the audio session type. Possible values are:

  • "auto"
    • : The default value. The user agent automatically chooses the audio session type based on the audio APIs used by the page, following a fixed priority order — see auto type selection for details.
  • "playback"
    • : Audio for media playback, such as video or music playback, podcasts, etc. This is an exclusive type that will pause other playback audio on the device, but may allow non-playback audio (such as notification sounds) to continue.
  • "transient"
    • : Transient audio, such as notification sounds. This type usually plays on top of other audio and may cause it to duck (reduce in volume).
  • "transient-solo"
    • : Transient solo audio, such as driving directions or voice prompts. This type pauses or mutes all other audio and plays exclusively. When the audio ends, previously playing audio may resume.
  • "ambient"
    • : Ambient audio that can mix with other types of audio. This is useful when users want to mix audio from multiple pages or applications.
  • "play-and-record"
    • : Audio for recording or real-time communication. This is appropriate when the microphone is being used or in video conferencing applications.

Examples

Setting the audio session type for media playback

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

// Play music
audioElement.play();

Setting up a video conference call

// 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;

Using transient audio for notifications

// Set transient type for a notification sound
navigator.audioSession.type = "transient";

// Play notification
notificationSound.play();

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。