开始
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-audio-session`, `@capgo/capacitor-audiosession`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/audiosession/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen 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-sessionbunx cap sync导入
标题:导入import { AudioSession } from '@capgo/capacitor-audio-session';API概述
标题:API概述currentOutputs
标题:当前输出获取当前激活的音频输出路由。
在Web和非iOS平台上,这个值会解析为一个空数组。
import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.currentOutputs();overrideOutput
overrideOutputoverride当前音频输出路由
overrideOutput speaker 强制通过内置扬声器播放,或
default 恢复系统选择的路由
import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.overrideOutput({} as OutputOverrideType);Type Reference
Type ReferenceAudioSessionPorts
AudioSessionPortsiOS设备上的可用音频输出路由
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';OverrideResult
标题:“OverrideResult”输出重写请求的结果。
export type OverrideResult = { success: boolean; message: string;};RouteChangeListener
标题:“RouteChangeListener”当音频路由发生变化时调用。
export type RouteChangeListener = (reason: RouteChangeReasons) => void;InterruptionListener
标题:“InterruptionListener”当音频会话被中断或结束时调用。
export type InterruptionListener = (type: InterruptionTypes) => void;RouteChangeReasons
“路由变化原因”部分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-视频播放器的实现细节