Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
## Description
|
||||
|
||||
Plugin to set volume of the music stream.
|
||||
|
||||
## Supported Platforms
|
||||
|
||||
Android
|
||||
|
||||
## Installation
|
||||
|
||||
Adding the Plugin to your project:
|
||||
```bash
|
||||
phonegap local plugin add https://github.com/Jiliac/phonegap-plugin-systemvolume.git
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
//set the sound to maximum
|
||||
window.system.setSystemVolume(1.0);
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||
id="com.jiliac.systemvolume"
|
||||
version="0.1.0">
|
||||
<name>System Volume</name>
|
||||
<description>PhoneGap System Volume Plugin</description>
|
||||
<license>MIT</license>
|
||||
<keywords>phonegap,volume</keywords>
|
||||
<repo>https://github.com/Jiliac/phonegap-plugin-systemvolume.git</repo>
|
||||
|
||||
<js-module src="www/systemvolume.js" name="SystemVolume">
|
||||
<clobbers target="window.system" />
|
||||
</js-module>
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="SystemVolume">
|
||||
<param name="android-package" value="com.jiliac.systemvolume.SystemVolume"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/SystemVolume.java" target-dir="src/com/jiliac/systemvolume" />
|
||||
|
||||
|
||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
</config-file>
|
||||
|
||||
</platform>
|
||||
|
||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
</config-file>
|
||||
</plugin>
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.jiliac.systemvolume;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Vibrator;
|
||||
|
||||
public class SystemVolume extends CordovaPlugin {
|
||||
public SystemVolume(){
|
||||
|
||||
}
|
||||
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
if(action.equals("setSystemVolume")) {
|
||||
this.setSystemVolume(args.getDouble(0));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
callbackContext.success();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSystemVolume(double volume) {
|
||||
AudioManager am = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
am.setStreamVolume(
|
||||
AudioManager.STREAM_MUSIC,
|
||||
(int) (am.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * volume),
|
||||
0);
|
||||
/*am.setStreamVolume(
|
||||
AudioManager.STREAM_SYSTEM,
|
||||
(int) (am.getStreamMaxVolume(AudioManager.STREAM_SYSTEM) * volume),
|
||||
0);
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
module.exports = {
|
||||
|
||||
setSystemVolume: function(volume) {
|
||||
exec(null, null, "SystemVolume", "setSystemVolume", [volume]);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user