Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.49 KB

README.md

File metadata and controls

67 lines (52 loc) · 1.49 KB

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 plugin
  • volumeControl.destroy(); Unset plugin
  • volumeControl.setVolume(float 0 <=> 1); Set volume
  • volumeControl.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);
});