Passer au contenu

Getting Started

Ce contenu n'est pas encore disponible dans votre langue.

Terminal window
bun add @capgo/capacitor-audio-session
bunx cap sync
import { AudioSession } from '@capgo/capacitor-audio-session';

Get the current active audio output routes.

On web and non-iOS platforms, this resolves to an empty array.

import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.currentOutputs();

Override the current audio output route.

Use speaker to force playback through the built-in speaker, or default to restore the system-selected route.

import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.overrideOutput({} as OutputOverrideType);

Available audio output routes on iOS.

export enum AudioSessionPorts {
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',
}

Output override type. - default: Use the system-selected route. - speaker: Force playback through the built-in speaker.

export type OutputOverrideType = 'default' | 'speaker';

Result of an output override request.

export type OverrideResult = {
success: boolean;
message: string;
};

Listener called when the audio route changes.

export type RouteChangeListener = (reason: RouteChangeReasons) => void;

Listener called when the audio session is interrupted or ends.

export type InterruptionListener = (type: InterruptionTypes) => void;
export enum RouteChangeReasons {
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',
}
export enum InterruptionTypes {
BEGAN = 'began',
ENDED = 'ended',
}

This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.