跳过内容

开始

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Terminal window
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-audio-session` plugin in my project.

如果您更喜欢手动设置,请运行以下命令安装插件,并按照以下平台特定的说明进行操作:

终端窗口
bun add @capgo/capacitor-audio-session
bunx cap sync
import { AudioSession } from '@capgo/capacitor-audio-session';

currentOutputs

标题:当前输出

获取当前激活的音频输出路由。

在Web和非iOS平台上,这个值会解析为一个空数组。

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

overrideOutput

overrideOutput

override当前音频输出路由

overrideOutput speaker 强制通过内置扬声器播放,或 default 恢复系统选择的路由

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

Type Reference

Type Reference

AudioSessionPorts

AudioSessionPorts

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',
}

OutputOverrideType

OutputOverrideType

输出重写类型。 - default: 使用系统选择的路由。 - speaker: 强制通过内置扬声器播放。

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

输出重写请求的结果。

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

当音频路由发生变化时调用。

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

当音频会话被中断或结束时调用。

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',
}

InterruptionTypes

“中断类型”部分
export enum InterruptionTypes {
BEGAN = 'began',
ENDED = 'ended',
}

本页面由插件生成 src/definitions.ts. 当公共 API 上游更改时,请重新运行同步

继续从 Getting Started

“继续从 Getting Started”部分

如果您正在使用 开始使用 为native媒体和界面行为打算,连接它与 使用@capgo/capacitor-音频会话 为native能力在使用@capgo/capacitor-音频会话中 使用@capgo/capacitor-直播活动 为native能力在使用@capgo/capacitor-直播活动中 @capgo/capacitor-直播活动 为@capgo/capacitor-直播活动的实现细节 使用@capgo/capacitor-视频播放器 为native能力在使用@capgo/capacitor-视频播放器中 @capgo/capacitor-视频播放器 为@capgo/capacitor-视频播放器的实现细节