Skip to content

thiagobrez/capacitor-volume-buttons

Repository files navigation

Important

This repository has been merged into @capacitor-community/volume-buttons, where is it going to be actively maintained

capacitor-volume-buttons

Hardware volume buttons listener for Capacitor

Install

npm install capacitor-volume-buttons
npx cap sync

Quick example

  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();
    };
  }, []);

API

addListener('volumeButtonPressed', ...)

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()

removeAllListeners() => Promise<void>

Removes all listeners for this plugin

Since: 1.0.0


Interfaces

PluginListenerHandle

Prop Type
remove () => Promise<void>

Type Aliases

VolumeButtonPressedListener

({ direction, }: VolumeButtonPressed): void

VolumeButtonPressed

{ direction: 'up' | 'down' }