跳过内容

开始获取

GitHub

您可以使用我们的 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-session
bunx cap sync
import { AudioSession } from '@capgo/capacitor-audio-session';

获取当前激活的音频输出路由。

在 web 和非 iOS 平台上,这将解析为一个空数组。

import { AudioSession } from '@capgo/capacitor-audio-session';
await AudioSession.currentOutputs();

覆盖当前音频输出路由。

使用 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

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上游更改时,请重新运行同步

继续从开始

继续从开始

如果您正在使用 开始 计划原生媒体和界面行为,连接它 使用@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。