Control volume and Receive volume events (iOS /Android)
- iOS
- Android
cordova plugin add cordova-simple-volume -S
volumeControl.init({options}, callbackVolumeChanges);
Initializes pluginvolumeControl.destroy();
Unset pluginvolumeControl.setVolume(float 0 <=> 1);
Set volumevolumeControl.getVolume();
Get volume, returns a promise with current volume
- volume: Set volume during initialization
- hideVolumeNotification: (iOS only) hides the volume UI during volume change
var options = {volume: 0.5, hideVolumeNotification:true};
//init
volumeControl.init(options, function(vol){
console.log("Volume changed" , vol);
});
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);
volumeControl.setVolume(0.5);
volumeControl.getVolume().then((vol) => {
console.log("Volume" , vol);
});