メニューに進む

Getting Started

GitHub

CapgoのAI-Assistedセットアップを使用してプラグインをインストールできます。AIツールに次のコマンドを使用してCapgoスキルを追加します。

ターミナル画面
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.

Manualセットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。

ターミナル画面
bun add @capgo/capacitor-audio-session
bunx cap sync
import { AudioSession } from '@capgo/capacitor-audio-session';

現在のアクティブなオーディオ出力ルートを取得します。

ウェブと非iOSプラットフォームでは、空の配列に解決されます。

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

現在のオーディオ出力ルートをオーバーライドします。

Use speaker を使用して、ビルトインスピーカーを通じて再生することを強制します。 default __CAPGO_KEEP_0__をシステムで選択されたルートに戻します。

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

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',
}

出力オーバーライドタイプ defaultシステムで選択されたルートを使用します。 speakerシステムで選択されたルートを強制します。

export type OutputOverrideType = 'default' | 'speaker';

出力オーバーライド要求の結果。

export type OverrideResult = {
success: boolean;
message: string;
};

オーディオルートが変更されたときに呼び出されるリスナー。

export type RouteChangeListener = (reason: RouteChangeReasons) => void;

オーディオセッションが中断されたり終了したときに呼び出されるリスナー。

export type InterruptionListener = (type: InterruptionTypes) => void;
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',
}
export enum InterruptionTypes {
BEGAN = 'began',
ENDED = 'ended',
}

このページはプラグインの src/definitions.tsパブリック API がアップストリームで変更された場合に再度同步を実行してください。

あなたが Getting Started ネイティブメディアとインターフェイスの動作を計画する場合、 Using @capgo/capacitor-audio-session Using @capgo/capacitor-audio-session @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-video-player, and @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-video-player.