快速入门
复制一条配置 prompt,包含安装步骤和该插件的完整 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`
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 APIs 针对 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. 中的实现细节