-
Notifications
You must be signed in to change notification settings - Fork 8
Added getVolume() #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ac6a087
6984a3f
c02d2a5
721022f
3c1a898
71e941a
dc05e3d
4e68adf
d765f8d
a46e2b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /test_project | ||
| .idea |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # cordova-volume-control | ||
| # cordova-simple-volume | ||
| Control volume and Receive volume events (iOS /Android) | ||
|
|
||
| ### Supported Platforms | ||
|
|
@@ -8,13 +8,14 @@ Control volume and Receive volume events (iOS /Android) | |
|
|
||
| ## Installation | ||
|
|
||
| cordova plugin add https://github.com/boedy/cordova-volume-control --save | ||
| cordova plugin add https://github.com/online-data-intelligence/cordova-simple-volume | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pointing to wrong repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just for my testing on my folk. I will put everything to point to the main repo |
||
|
|
||
| ### 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 | ||
|
|
@@ -32,3 +33,35 @@ volumeControl.init(options, function(vol){ | |
| console.log("Volume changed" , vol); | ||
| }); | ||
| ``` | ||
|
|
||
| ### cordova ios volumedownbutton / volumeupbutton events polyfill | ||
| ```js | ||
| 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 | ||
| ```js | ||
| volumeControl.setVolume(0.5); | ||
| ``` | ||
|
|
||
| ### getVolume() example | ||
| ```js | ||
| volumeControl.getVolume().then((vol) => { | ||
| console.log("Volume" , vol); | ||
| }); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "cordova-simple-volume", | ||
| "version": "1.0.2", | ||
| "description": "Cordova plugin which notifies when the user presses the volume buttons of the device", | ||
| "cordova": { | ||
| "id": "cordova-simple-volume", | ||
| "platforms": [ "android", "ios" ] | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/online-data-intelligence/cordova-simple-volume.git" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just for my testing on my folk. I will put everything to point to the main repo |
||
| }, | ||
| "keywords": [ "ecosystem:cordova", "cordova-android", "cordova-ios", "volume", "buttons" ], | ||
| "author": "Boudewijn Geiger", | ||
| "license": "Apache 2.0", | ||
| "bugs": { | ||
| "url": "https://github.com/online-data-intelligence/cordova-simple-volume/issues" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong repo |
||
| }, | ||
| "homepage": "https://github.com/boedy/cordova-volume-control" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,19 @@ module.exports = { | |
| init: function (options, successCallback, errorCallback) { | ||
| cordova.exec(successCallback, errorCallback, "VolumeControl", "initCommand", [options]); | ||
| }, | ||
| destroy: function(){ | ||
| destroy: function () { | ||
| cordova.exec(null, null, "VolumeControl", "destroyCommand", null); | ||
| }, | ||
| setVolume: function(volume){ | ||
| setVolume: function (volume) { | ||
| cordova.exec(null, null, "VolumeControl", "setVolumeCommand", [volume]); | ||
| }, | ||
| getVolume: function () { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS does not support es6 syntax. So arrow functions (=>) don't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats strange as the plugin works on my iPhone? I will remove and test without the arrow functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah it seems it works on the newer iOS safari versions . It would be good to support older versions too though (e.g iPod touch 5th generation is on iOS 9). |
||
| return new Promise((resolve, reject) => { | ||
| cordova.exec((volume) => { | ||
| resolve(parseFloat(volume)) | ||
| }, () => { | ||
| reject("error getting volume") | ||
| }, "VolumeControl", "getVolumeCommand"); | ||
| }) | ||
| } | ||
| }; | ||
|
|
||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is see you changed the name of the plugin. I'm assuming this is because another plugin has claimed the npm namespace. I'm open to changing this, but it would be good if releases of this package would be in sync with this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change the name I just folked a folk which had already changed the name? I have no preference on name