@capacitor-community/volume-buttons

中文文档
8.0.1发布于 2026/07/24MITTypeScriptESM + CJS零依赖近 30 天下载 1.4万

Capacitor Volume Buttons. The plugin enables to listen to hardware volume button presses

原始使用文档
文档目录16 节
  1. Capacitor Volume Buttons Plugin
  2. Table of Contents
  3. Maintainers
  4. About
  5. Plugin versions
  6. Supported Platforms
  7. Installation
  8. API
  9. isWatching()
  10. watchVolume(...)
  11. clearWatch()
  12. Interfaces
  13. Type Aliases
  14. Usage
  15. Add volume button listener in the app
  16. Remove volume button listener in the app


Capacitor Volume Buttons Plugin

@capacitor-community/volume-buttons

Capacitor community plugin to listen to hardware volume button presses


Table of Contents

Maintainers

MaintainerGitHubActive
ryaaryaayes

About

This plugins allows to listen for the events fired when the user presses the hardware volume up or down button of the device. An object that contains only one property is passed to the callback - see VolumeButtonsResult. This plugin contains code derived from or inspired by https://github.com/CipherBitCorp/VolumeButtonHandler and https://github.com/thiagobrez/capacitor-volume-buttons plugins.


Features:

  • support receiving events when the volume is max or min (make sure to use disableSystemVolumeHandler on iOS platform - see VolumeButtonsOptions)
  • keep receiving events after the application sent to and returns from the background
  • supports Android and iOS platforms

NOTE: The plugin version 8.x is compatible with Capacitor 8

Plugin versions

Capacitor versionPlugin version
8.x8.x
7.x7.x
6.x6.x
5.x1.x

Supported Platforms

  • iOS
  • Android

Installation

npm install @capacitor-community/volume-buttons
npx cap sync

API

isWatching()

isWatching() => Promise<GetIsWatchingResult>

Get the watch status of the volume buttons.

Returns: Promise<GetIsWatchingResult>

Since: 1.0.1


watchVolume(...)

watchVolume(options: VolumeButtonsOptions, callback: VolumeButtonsCallback) => Promise<CallbackID>

Set up a watch for he hardware volume buttons changes

ParamType
optionsVolumeButtonsOptions
callbackVolumeButtonsCallback

Returns: Promise<string>

Since: 1.0.0


clearWatch()

clearWatch() => Promise<void>

Clear the existing watch

Since: 1.0.0


Interfaces

GetIsWatchingResult

PropTypeDescriptionSince
valuebooleanIf the volume buttons are being watched.1.0.1

VolumeButtonsOptions

PropTypeDescriptionSince
disableSystemVolumeHandlerbooleanThis parameter can be used to disable the system volume handler (iOS only). If this is true, when up or down volume button is tapped, the system volume will always be reset to either the initial volume (the volume which was current when the volume buttons are started to be tracked/listened) or to 0.05 if the initial volume is less then 0.05 or to 0.95 if the initial volume is greater then 0.95.1.0.0
suppressVolumeIndicatorbooleanThis parameter can be used to suppress/hide the system volume indicator (Android only, it is never shown on iOS already). If this is true, when up or down volume button is tapped, the system volume indicator will not be shown. The default value is false.1.0.2

VolumeButtonsResult

PropTypeDescriptionSince
direction'up' | 'down'This indicates either the volume up or volume down button was pressed.1.0.0

Type Aliases

VolumeButtonsCallback

(result: VolumeButtonsResult, err?: any): void

CallbackID

string

Usage

Please also see example-app for a complete example.

Add volume button listener in the app

import { VolumeButtons } from '@capacitor-community/volume-buttons';

const options: VolumeButtonsOptions = {};
const callback: VolumeButtonsCallback = (result: VolumeButtonsResult, err?: any) => {
  console.log('result', result);
};
if (this.platform.is('ios')) {
  options.disableSystemVolumeHandler = true;
} else if (this.platform.is('android')) {
  options.suppressVolumeIndicator = true;
}
await VolumeButtons.watchVolume(options, callback);

Remove volume button listener in the app

import { VolumeButtons } from '@capacitor-community/volume-buttons';

await VolumeButtons.clearWatch();

版本与发布记录

@capacitor-community/volume-buttons 共发布 8 个版本,首次发布于 2024/01/08;过去 12 个月发布了 2 个版本。

版本发布日期距今
8.0.1latest2026/07/243 个月前
8.0.02026/01/289 个月前
7.0.02025/01/281.8 年前
6.0.12024/07/232 年前
6.0.02024/04/232 年前
1.0.22024/04/092 年前

关于 @capacitor-community/volume-buttons 的常见问题

@capacitor-community/volume-buttons 是什么?

Capacitor Volume Buttons. The plugin enables to listen to hardware volume button presses

如何安装 @capacitor-community/volume-buttons?

在项目目录运行 npm install @capacitor-community/volume-buttons,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-community/volume-buttons 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-community/volume-buttons 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-community/volume-buttons 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@capacitor-community/volume-buttons 可以商用吗?

@capacitor-community/volume-buttons 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/volume-buttons 的下载量有多少?

根据 npm 官方下载统计,@capacitor-community/volume-buttons 在 2026/10/09 – 2026/11/07 这 30 天内被下载 13,863 次,日均约 462 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-community/volume-buttons 还在维护吗?

最新版本 8.0.1 发布于 2026/07/24(3 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/01/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。