diff --git a/framework/assets/js/media.js b/framework/assets/js/media.js index de955c66..f530025c 100755 --- a/framework/assets/js/media.js +++ b/framework/assets/js/media.js @@ -155,6 +155,13 @@ Media.prototype.release = function() { PhoneGap.exec(null, null, "Media", "release", [this.id]); }; +/** + * Adjust the volume. + */ +Media.prototype.setVolume = function(volume) { + PhoneGap.exec(null, null, "Media", "setVolume", [this.id, volume]); +}; + /** * List of media objects. * PRIVATE diff --git a/framework/src/com/phonegap/AudioHandler.java b/framework/src/com/phonegap/AudioHandler.java index 9673b076..e7f77d90 100755 --- a/framework/src/com/phonegap/AudioHandler.java +++ b/framework/src/com/phonegap/AudioHandler.java @@ -7,17 +7,15 @@ */ package com.phonegap; -import java.util.HashMap; -import java.util.Map.Entry; - +import android.content.Context; +import android.media.AudioManager; +import com.phonegap.api.Plugin; +import com.phonegap.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; -import com.phonegap.api.Plugin; -import com.phonegap.api.PluginResult; - -import android.content.Context; -import android.media.AudioManager; +import java.util.HashMap; +import java.util.Map.Entry; /** * This class called by PhonegapActivity to play and record audio. @@ -71,8 +69,13 @@ public class AudioHandler extends Plugin { } else if (action.equals("stopPlayingAudio")) { this.stopPlayingAudio(args.getString(0)); - } - else if (action.equals("getCurrentPositionAudio")) { + } else if (action.equals("setVolume")) { + try { + this.setVolume(args.getString(0), Float.parseFloat(args.getString(1))); + } catch (NumberFormatException nfe) { + //no-op + } + } else if (action.equals("getCurrentPositionAudio")) { float f = this.getCurrentPositionAudio(args.getString(0)); return new PluginResult(status, f); } @@ -295,5 +298,20 @@ public class AudioHandler extends Plugin { else { return -1; } - } + } + + /** + * Set the volume for an audio device + * + * @param id The id of the audio player + * @param volume Volume to adjust to 0.0f - 1.0f + */ + public void setVolume(String id, float volume) { + AudioPlayer audio = this.players.get(id); + if (audio != null) { + audio.setVolume(volume); + } else { + System.out.println("AudioHandler.setVolume() Error: Unknown Audio Player " + id); + } + } } diff --git a/framework/src/com/phonegap/AudioPlayer.java b/framework/src/com/phonegap/AudioPlayer.java index 2d99fdbc..df90795a 100755 --- a/framework/src/com/phonegap/AudioPlayer.java +++ b/framework/src/com/phonegap/AudioPlayer.java @@ -7,8 +7,6 @@ */ package com.phonegap; -import java.io.File; -import java.io.IOException; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; @@ -18,6 +16,9 @@ import android.media.MediaRecorder; import android.os.Environment; import android.util.Log; +import java.io.File; +import java.io.IOException; + /** * This class implements the audio playback and recording capabilities used by PhoneGap. * It is called by the AudioHandler PhoneGap class. @@ -417,4 +418,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On this.state = state; } + + /** + * Set the volume for audio player + * + * @param volume + */ + public void setVolume(float volume) { + this.mPlayer.setVolume(volume, volume); + } }