7.1.22 • Published 6 months ago

capacitor-plugin-audiosession-bluetooth v7.1.22

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

capacitor-plugin-audiosession-bluetooth

This plugin works on iOS only.

This plugin is a fork of studiokloek/capacitor-plugin-audiosession (which is a port of cordova-plugin-audioroute) with additional features for automatic audio device switching. It provides:

  • Bluetooth device auto-switching support
  • Priority-based output device selection
  • Real-time audio route change detection
  • Customizable device priority order

Key Features

  • Automatically switches to connected Bluetooth devices
  • Configurable device priority (wired > Bluetooth > built-in speaker)
  • Handles audio interruptions and route changes
  • Supports iOS audio session management

Usage Example

import { AudioSession, AudioSessionPorts } from 'capacitor-plugin-audiosession-bluetooth';

// Configure on app startup
await AudioSession.configure({
  autoSwitchBluetooth: true,
  priorityOrder: [
    AudioSessionPorts.LINE_OUT, // Wired connection
    AudioSessionPorts.HEADPHONES, // Headphone jack
    AudioSessionPorts.BLUETOOTH_A2DP, // Bluetooth audio
    AudioSessionPorts.BLUETOOTH_HFP, // Bluetooth headset
    AudioSessionPorts.BLUETOOTH_LE, // Bluetooth Low Energy
    AudioSessionPorts.AIR_PLAY, // AirPlay
    AudioSessionPorts.BUILT_IN_SPEAKER, // Built-in speaker
  ],
});

// Listen for route changes
AudioSession.addListener('routeChanged', (reason) => {
  console.log('Audio route changed:', reason);
});

Key Features Demonstrated:

  • Automatic device switching based on priority
  • Real-time route change monitoring
  • Custom priority configuration

Install

npm install @studiokloek/capacitor-plugin-audiosession
npx cap sync

For now this plugin works only in Capacitor 4.0+.

API

currentOutputs()

currentOutputs() => Promise<AudioSessionPorts[]>

Returns: Promise<AudioSessionPorts[]>


overrideOutput(...)

overrideOutput(type: OutputOverrideType) => Promise<OverrideResult>
ParamType
typeOutputOverrideType

Returns: Promise<OverrideResult>


addListener('routeChanged', ...)

addListener(eventName: 'routeChanged', listenerFunc: RouteChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'routeChanged'
listenerFuncRouteChangeListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('interruption', ...)

addListener(eventName: 'interruption', listenerFunc: InterruptionListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'interruption'
listenerFuncInterruptionListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


configure(...)

configure(options: AudioSessionOptions) => Promise<void>
ParamType
optionsAudioSessionOptions

Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

AudioSessionOptions

PropType
autoSwitchBluetoothboolean
priorityOrderAudioSessionPorts[]

Type Aliases

OverrideResult

{ success: boolean; message: string; }

OutputOverrideType

'default' | 'speaker'

RouteChangeListener

(reason: RouteChangeReasons): void

InterruptionListener

(type: InterruptionTypes): void

Enums

AudioSessionPorts

MembersValue
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

MembersValue
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

MembersValue
BEGAN'began'
ENDED'ended'

License

MIT

Author

Martijn Swart https://studiokloek.nl

Based on work from: Saúl Ibarra Corretgé saghul@gmail.com

7.1.22

6 months ago

7.1.21

7 months ago

7.1.20

7 months ago

7.1.19

7 months ago

7.1.18

7 months ago

7.1.17

7 months ago

7.1.16

7 months ago

7.1.15

7 months ago

7.1.14

7 months ago

7.1.13

7 months ago

7.1.12

7 months ago

7.1.11

7 months ago

7.1.10

7 months ago

7.1.9

7 months ago

7.1.8

7 months ago

7.1.7

7 months ago

7.1.6

7 months ago

7.1.5

7 months ago

7.1.4

7 months ago

7.1.3

7 months ago

7.1.2

7 months ago

7.1.1

7 months ago

7.1.0

7 months ago

7.0.30

7 months ago

7.0.29

7 months ago

7.0.28

7 months ago

7.0.27

7 months ago

7.0.26

7 months ago

7.0.25

7 months ago

7.0.24

7 months ago

7.0.23

7 months ago

7.0.22

7 months ago

7.0.21

7 months ago

7.0.20

7 months ago

7.0.17

7 months ago

7.0.16

7 months ago

7.0.15

7 months ago

7.0.14

7 months ago

7.0.13

7 months ago

7.0.12

7 months ago

7.0.11

7 months ago

7.0.10

7 months ago

7.0.9

7 months ago

7.0.8

7 months ago

7.0.7

7 months ago

7.0.6

7 months ago

7.0.5

7 months ago

7.0.4

7 months ago

7.0.3

7 months ago

7.0.2

7 months ago

7.0.1

7 months ago

7.0.0

7 months ago