This capacitor plugin allows iOS applications to get notified audio about interrupts & route changes (for example when a headset is connected), and also query and override the audio device in use.
npm install @studiokloek/capacitor-plugin-audiosessionThis plugin works on iOS only.
This plugin is a port of
``bash`
yarn add @studiokloek/capacitor-plugin-audiosession
npx cap sync
For now this plugin works only in Capacitor 4.0+.
* currentOutputs()
* overrideOutput(...)
* addListener('routeChanged', ...)
* addListener('interruption', ...)
* Interfaces
* Type Aliases
* Enums
`typescript`
currentOutputs() => Promise
Returns: Promise<AudioSessionPorts[]>
--------------------
`typescript`
overrideOutput(type: OutputOverrideType) => Promise
| Param | Type |
| ---------- | ----------------------------------------------------------------- |
| type | OutputOverrideType |
Returns: Promise<OverrideResult>
--------------------
`typescript`
addListener(eventName: 'routeChanged', listenerFunc: RouteChangeListener) => Promise
| Param | Type |
| ------------------ | ------------------------------------------------------------------- |
| eventName | 'routeChanged' |
| listenerFunc | RouteChangeListener |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
addListener(eventName: 'interruption', listenerFunc: InterruptionListener) => Promise
| Param | Type |
| ------------------ | --------------------------------------------------------------------- |
| eventName | 'interruption' |
| listenerFunc | InterruptionListener |
Returns: Promise<PluginListenerHandle>
--------------------
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
#### OverrideResult
{ success: boolean; message: string; }
#### OutputOverrideType
'default' | 'speaker'
#### RouteChangeListener
(reason: RouteChangeReasons): void
#### InterruptionListener
(type: InterruptionTypes): void
#### AudioSessionPorts
| Members | Value |
| ----------------------- | ------------------------------- |
| AIR_PLAY | 'airplay' |
| BLUETOOTH_LE | 'bluetooth-le' |
| BLUETOOTH_HFP | 'bluetooth-hfp' |
| BLUETOOTH_A2DP | 'bluetooth-a2dp' |
| BUILT_IN_SPEAKER | 'builtin-speaker' |
| BUILT_IN_RECEIVER | 'builtin-receiver' |
| HDMI | 'hdmi' |
| HEADPHONES | 'headphones' |
| LINE_OUT | 'line-out' |
#### RouteChangeReasons
| Members | Value |
| ------------------------------------ | --------------------------------------------- |
| NEW_DEVICE_AVAILABLE | 'new-device-available' |
| OLD_DEVICE_UNAVAILABLE | 'old-device-unavailable' |
| CATEGORY_CHANGE | 'category-change' |
| OVERRIDE | 'override' |
| WAKE_FROM_SLEEP | 'wake-from-sleep' |
| NO_SUITABLE_ROUTE_FOR_CATEGORY | 'no-suitable-route-for-category' |
| ROUTE_CONFIGURATION_CHANGE | 'route-config-change' |
| UNKNOWN | 'unknown' |
#### InterruptionTypes
| Members | Value |
| ----------- | -------------------- |
| BEGAN | 'began' |
| ENDED` | 'ended' |
MIT
Martijn Swart
Based on work from: Saúl Ibarra Corretgé