指南
关于音量按钮的教程
使用 @capgo/capacitor-volume-buttons
Capacitor 音量按钮插件,用于检测硬件音量按钮按压。
安装
bun add @capgo/capacitor-volume-buttons
bunx cap sync
此插件暴露了什么
addListener- 监听硬件音量按钮的按压。removeAllListeners- 移除此插件的所有监听器。getPluginVersion- 获取本地 Capacitor 插件版本。
示例使用
addListener
监听硬件音量按钮的按压。
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();
removeAllListeners
移除此插件的所有监听器。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();
getPluginVersion
获取本地 Capacitor 插件版本。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();
console.log('Plugin version:', version);
全局参考
- GitHub: https://github.com/Cap-go/capacitor-volume-buttons/
- 文档: /docs/plugins/volume-buttons/
继续使用 @capgo/capacitor-volume-buttons
如果您正在使用 使用 @capgo/capacitor-volume-buttons 与 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-volume-buttons 在 @capgo/capacitor-volume-buttons 中了解实现细节 for the implementation detail in @capgo/capacitor-volume-buttons, 在 Getting Started 中了解实现细节 __CAPGO_KEEP_0__ 插件目录 了解 Capgo 插件目录 中的产品工作流程 Capgo 由 __CAPGO_KEEP_1__ 提供的插件 了解 Capacitor 由 Capgo 提供的插件 中的实现细节 for the implementation detail in Capacitor Plugins by Capgo, and 在添加或更新插件中 为添加或更新插件的实现细节.