/capacitor-volume-buttons

Hardware volume buttons listener for Capacitor

Primary LanguageSwiftApache License 2.0Apache-2.0

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' }