mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 08:21:04 +08:00
exposing volume control
This commit is contained in:
parent
8c7db9aa32
commit
ad8086fab5
@ -155,6 +155,13 @@ Media.prototype.release = function() {
|
|||||||
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
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.
|
* List of media objects.
|
||||||
* PRIVATE
|
* PRIVATE
|
||||||
|
@ -7,17 +7,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import android.content.Context;
|
||||||
import java.util.Map.Entry;
|
import android.media.AudioManager;
|
||||||
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PluginResult;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import com.phonegap.api.Plugin;
|
import java.util.HashMap;
|
||||||
import com.phonegap.api.PluginResult;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class called by PhonegapActivity to play and record audio.
|
* This class called by PhonegapActivity to play and record audio.
|
||||||
@ -71,8 +69,13 @@ public class AudioHandler extends Plugin {
|
|||||||
}
|
}
|
||||||
else if (action.equals("stopPlayingAudio")) {
|
else if (action.equals("stopPlayingAudio")) {
|
||||||
this.stopPlayingAudio(args.getString(0));
|
this.stopPlayingAudio(args.getString(0));
|
||||||
|
} 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")) {
|
} else if (action.equals("getCurrentPositionAudio")) {
|
||||||
float f = this.getCurrentPositionAudio(args.getString(0));
|
float f = this.getCurrentPositionAudio(args.getString(0));
|
||||||
return new PluginResult(status, f);
|
return new PluginResult(status, f);
|
||||||
}
|
}
|
||||||
@ -296,4 +299,19 @@ public class AudioHandler extends Plugin {
|
|||||||
return -1;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.MediaPlayer.OnCompletionListener;
|
import android.media.MediaPlayer.OnCompletionListener;
|
||||||
@ -18,6 +16,9 @@ import android.media.MediaRecorder;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the audio playback and recording capabilities used by PhoneGap.
|
* This class implements the audio playback and recording capabilities used by PhoneGap.
|
||||||
* It is called by the AudioHandler PhoneGap class.
|
* It is called by the AudioHandler PhoneGap class.
|
||||||
@ -417,4 +418,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the volume for audio player
|
||||||
|
*
|
||||||
|
* @param volume
|
||||||
|
*/
|
||||||
|
public void setVolume(float volume) {
|
||||||
|
this.mPlayer.setVolume(volume, volume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user