Skip to content

Latest commit

 

History

History
134 lines (88 loc) · 3.62 KB

audio.md

File metadata and controls

134 lines (88 loc) · 3.62 KB

audio

Documentation: Chrome Audio API

A promise-based wrapper for the Chrome audio API.

Methods

Events


isAvailableAudio

isAvailableAudio(method?: ApiMethodName<typeof chrome.audio>): boolean

The optional method is a native function name, for example isAvailableAudio("getDevices"). Import the public ApiMethodName type from @addon-core/browser for your own typed helpers. This checks callable presence without invoking the method; permissions and argument support still require handling.

Returns true when the audio namespace is present on the API selected by browser() in the current context. Returns false if the namespace or WebExtension environment is absent, or if accessing it throws. The check is synchronous, does not log, and reads the current API on every call without caching. Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable. Neither form verifies permissions, argument support, or a successful operation. See method availability.

import {isAvailableAudio} from "@addon-core/browser";

if (isAvailableAudio()) {
    // The namespace is present; handle operation-specific failures when using it.
}

getAudioDevices

getAudioDevices(filter?: chrome.audio.DeviceFilter): Promise<chrome.audio.AudioDeviceInfo[]>

Retrieves the list of available audio devices, optionally filtered.

getAudioMute

getAudioMute(streamType: chrome.audio.StreamType): Promise<boolean>

Retrieves the system-wide mute state of the specified audio stream type.

setAudioActiveDevices

setAudioActiveDevices(ids?: chrome.audio.DeviceIdLists): Promise<void>

Sets the lists of active input and/or output devices.

setAudioMute

setAudioMute(streamType: chrome.audio.StreamType, isMuted: boolean): Promise<void>

Sets the mute state for the specified audio stream type.

setAudioProperties

setAudioProperties(id: string, properties?: chrome.audio.DeviceProperties): Promise<void>

Updates properties for the specified audio device.

onAudioDeviceListChanged

onAudioDeviceListChanged(
  callback: (devices: chrome.audio.AudioDeviceInfo[]) => void
): () => void

Adds a listener that fires when audio devices are added or removed. Returns an unsubscribe function.

onAudioLevelChanged

onAudioLevelChanged(
  callback: (event: chrome.audio.LevelChangedEvent) => void
): () => void

Adds a listener that fires when sound level changes for an active audio device. Returns an unsubscribe function.

onAudioMuteChanged

onAudioMuteChanged(
  callback: (event: chrome.audio.MuteChangedEvent) => void
): () => void

Adds a listener that fires when the mute state of the audio input or output changes. Returns an unsubscribe function.