Important
This repository has been merged into @capacitor-community/volume-buttons, where is it going to be actively maintained
Hardware volume buttons listener for Capacitor
npm install capacitor-volume-buttons
npx cap sync
useEffect(() => {
const onVolumeButtonPressed = ({ direction }: VolumeButtonPressed) => {
if (direction === 'up') {
console.log('Volume up pressed!');
} else {
console.log('Volume down pressed!');
}
};
CapacitorVolumeButtons.addListener('volumeButtonPressed', onVolumeButtonPressed);
return () => {
CapacitorVolumeButtons.removeAllListeners();
};
}, []);
addListener(event: 'volumeButtonPressed', listenerFunc: VolumeButtonPressedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
Listen for presses on the hardware volume buttons
Param | Type |
---|---|
event |
'volumeButtonPressed' |
listenerFunc |
VolumeButtonPressedListener |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
removeAllListeners() => Promise<void>
Removes all listeners for this plugin
Since: 1.0.0
Prop | Type |
---|---|
remove |
() => Promise<void> |
({ direction, }: VolumeButtonPressed): void
{ direction: 'up' | 'down' }