开始
复制一个设置提示,包含安装步骤和该插件的完整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.
安装
标题为“安装”bun add @capgo/capacitor-audio-sessionbunx cap syncimport { AudioSession } from '@capgo/capacitor-audio-session';API 概述
Section titled “API 概述”currentOutputs
Section titled “当前输出”获取当前激活的音频输出路由。
在 web 和非 iOS 平台上,这将解析为一个空数组。
import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.currentOutputs();overrideOutput
Section titled “覆盖输出”覆盖当前音频输出路由。
使用 speaker 强制通过内置扬声器播放
default to restore the system-selected route.
import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.overrideOutput({} as OutputOverrideType);类型参考
类型参考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
输出重写类型输出重写类型: 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
RouteChangeReasonsexport 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
InterruptionTypesexport enum InterruptionTypes { BEGAN = 'began', ENDED = 'ended',}真实来源
标题:真实来源本页面由插件生成 src/definitions.ts当公共API上游发生变化时,请重新运行同步
继续从开始
标题:继续从开始如果您正在使用 开始 来规划原生媒体和界面行为,连接它到 使用@capgo/capacitor-音频会话 为原生能力在使用@capgo/capacitor-音频会话 使用 @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