Skip to content

Control volume and Receive volume events (iOS /Android)

Notifications You must be signed in to change notification settings

injitools/cordova-simple-volume

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
});

About

Control volume and Receive volume events (iOS /Android)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 49.5%
  • Java 44.2%
  • JavaScript 6.3%