メインコンテンツへスキップ

はじめに

GitHub

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

ターミナルウィンドウ
bunx 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-volume-buttons` plugin in my project.

手動設定(Manual Setup)を行う場合は、以下のコマンドを実行してプラグインをインストールし、各プラットフォームごとの手順に従ってください:

ターミナルウィンドウ
bun add @capgo/capacitor-volume-buttons
bunx cap sync
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';

クイックスタート

「Quick start」セクション
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const listener = await VolumeButtons.addListener(
'volumeButtonPressed',
(event) => {
console.log(`Volume ${event.direction} button pressed`);
}
);
// Remove listener when done
await listener.remove();
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();
console.log('Plugin version:', version);
  • リスナー: 画面のアンマウント時に解除されます。
  • ネイティブ同期: 実行 bunx cap sync プラグインのアップグレード後に。
  • 信頼できる唯一の情報源 (Source of truth): 信頼 src/definitions.ts GitHub リポジトリ内の。

ハードウェアの音量ボタンのプレスを検知します。

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const listener = await VolumeButtons.addListener(
'volumeButtonPressed',
(event) => {
console.log(`Volume ${event.direction} button pressed`);
}
);
// Remove listener when done
await listener.remove();

このプラグインのすべてのリスナーを削除します。

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();

ネイティブの Capacitor プラグインのバージョンを取得します。

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();
console.log('Plugin version:', version);

ボリュームボタンのイベント用リスナー関数です。

export type VolumeButtonListener = (event: VolumeButtonPressed) => void;

ボリュームボタンが押された時のイベントデータです。

export interface VolumeButtonPressed {
/** Direction of the button press */
direction: VolumeButtonDirection;
}

音量ボタンが押された方向。

export type VolumeButtonDirection = 'up' | 'down';

信頼できる唯一の情報源

「Source Of Truth」セクション

このページはプラグインの src/definitions.tsから生成されています。上流の API が変更された場合は、再度 sync を実行してください。

以下を使用している場合: はじめに dashboard や API の運用を計画し、これと連携させるには @capgo/capacitor-volume-buttons の使用方法 @capgo/capacitor-volume-buttons でネイティブ機能を使用する場合、 API の概要 API Overview の実装の詳細については、 はじめに Introduction の実装の詳細については、 API キー API Keys の実装の詳細については、 デバイス Devices の実装の詳細については。