开始获取
复制一个包含安装步骤和本插件完整 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.
您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-audio-session` plugin in my project.如果您prefer Manual Setup,安装插件并运行以下命令并遵循以下平台特定的说明:
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。