mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
added audio output setting for android
This commit is contained in:
@@ -2,6 +2,8 @@ package com.nitobi.phonegap;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaRecorder;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
@@ -13,9 +15,11 @@ public class AudioHandler implements OnCompletionListener {
|
||||
private boolean isPlaying = false;
|
||||
private String recording;
|
||||
private String saveFile;
|
||||
private Context mCtx;
|
||||
|
||||
public AudioHandler(String file) {
|
||||
public AudioHandler(String file, Context ctx) {
|
||||
this.recording = file;
|
||||
this.mCtx = ctx;
|
||||
}
|
||||
|
||||
public void startRecording(String file){
|
||||
@@ -99,4 +103,25 @@ public class AudioHandler implements OnCompletionListener {
|
||||
return duration;
|
||||
} else { return -1; }
|
||||
}
|
||||
|
||||
protected void setAudioOutputDevice(String output){
|
||||
System.out.println ("Change audio setting to be "+output);
|
||||
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (output.contains("Speaker"))
|
||||
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||
else if (output.contains("Earpiece")){
|
||||
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
||||
}else
|
||||
System.out.println("input error");
|
||||
|
||||
}
|
||||
protected int getAudioOutputDevice(){
|
||||
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE)
|
||||
return 1;
|
||||
else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER)
|
||||
return 2;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user