快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
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`
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.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-audio-session` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
npm install @capgo/capacitor-audio-sessionnpx cap sync导入
“导入”章节import { AudioSession } from '@capgo/capacitor-audio-session';快速入门
章节标题为“快速入门”import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.overrideOutput('speaker');常见坑点
章节标题为“常见陷阱”- iOS 重点:routing API 针对 iOS audio session 行为。
- 恢复: 调用
overrideOutput('default')在通话结束后。 - 顺序: 在 Twilio 或媒体插件启动前配置。
API 概览
章节标题:“API 概览”currentOutputs
标题为“currentOutputs”的章节获取当前活动的音频输出路由。
在 Web 和非 iOS 平台上,这会返回一个空数组。
import { AudioSession } from '@capgo/capacitor-audio-session';
const result = await AudioSession.currentOutputs();console.log(result);overrideOutput
标题为“overrideOutput”的章节覆盖当前的音频输出路由。
使用 speaker 强制通过内置扬声器播放,或
default 恢复系统默认的音频路由。
import { AudioSession } from '@capgo/capacitor-audio-session';
const result = await AudioSession.overrideOutput('default');console.log(result);类型参考
“类型参考” 章节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';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
标题为 “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
标题为 “InterruptionTypes” 的章节export enum InterruptionTypes { BEGAN = 'began', ENDED = 'ended',}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 来规划原生媒体和界面行为,并将其与 使用 @capgo/capacitor-audio-session 在“使用 @capgo/capacitor-audio-session”中实现原生能力, 使用 @capgo/capacitor-live-activities 用于使用 @capgo/capacitor-live-activities 时的原生能力, @capgo/capacitor-live-activities 在 @capgo/capacitor-live-activities 中的实现细节, 使用 @capgo/capacitor-video-player 有关使用 @capgo/capacitor-video-player 时的原生能力,以及 @capgo/capacitor-video-player 关于 @capgo/capacitor-video-player. 中的实现细节