cordova-simple-volume
v1.0.4
Published
Cordova plugin which notifies when the user presses the volume buttons of the device
Downloads
11
Maintainers
Readme
cordova-simple-volume
Control volume and Receive volume events (iOS /Android)
Supported Platforms
- iOS
- Android
Installation
cordova plugin add cordova-simple-volume -S
Methods
volumeControl.init({options}, callbackVolumeChanges);
Initializes pluginvolumeControl.destroy();
Unset pluginvolumeControl.setVolume(float 0 <=> 1);
Set volumevolumeControl.getVolume();
Get volume, returns a promise with current volume
volumeControl.init options parameter
- volume: Set volume during initialization
- hideVolumeNotification: (iOS only) hides the volume UI during volume change
Quick Example
var options = {volume: 0.5, hideVolumeNotification:true};
//init
volumeControl.init(options, function(vol){
console.log("Volume changed" , vol);
});
cordova ios volumedownbutton / volumeupbutton events polyfill
document.addEventListener("deviceready", () => {
var curVolume = null
if (cordova.platformId === 'ios') {
volumeControl.init({}, (vol) => {
if (curVolume !== null) {
if (curVolume <= vol) {
document.dispatchEvent(new Event('volumedownbutton'))
} else {
document.dispatchEvent(new Event('volumeupbutton'))
}
}
curVolume = vol
console.log("Volume changed", vol);
});
}
}, false);
setVolume() example
volumeControl.setVolume(0.5);
getVolume() example
volumeControl.getVolume().then((vol) => {
console.log("Volume" , vol);
});