0.0.11 • Published 2 years ago

background-volume-buttons v0.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

background-volume-buttons

This capacitor.js plugin listens for and reacts to volume button presses when the app is in the background

import { App } from '@capacitor/app';
import { BackgroundVolumeButtonListener } from "background-volume-buttons";
        
App.addListener('appStateChange', ({ isActive }) => {
    console.log('App state changed. Is active?', isActive);
    if (!isActive) {
        console.debug("App going inactive / background")
        BackgroundVolumeButtonListener.startListening({
            timeout: 1000,
            triggerCount: 3,
            listenerName: "volumeEventTriggered"
        })
    } else {
        BackgroundVolumeButtonListener.stopListening()
    }
});

// Later
BackgroundVolumeButtonListener.addListener("volumeEventTriggered", async () => {
    // do stuff
}

Install

npm install background-volume-buttons
npx cap sync

API

startListening(...)

startListening(options: BackgroundVolumeButtonListenerOptions) => Promise<void>

Adds a listener to the volume buttons and fires an event when the volume is changed.

ParamType
optionsBackgroundVolumeButtonListenerOptions

stopListening()

stopListening() => Promise<void>

Removes above listener


Interfaces

BackgroundVolumeButtonListenerOptions

PropTypeDescription
triggerCountnumberThe number of times the volume should be changed before the event is fired. Defaults to 3
timeoutnumberThe max time in milliseconds before the triggerCount resets. Defaults to 1000
listenerNamestringRequired. The string name of the listener you would like the event to broadcast to i.e. volumeTriggered
0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago