Example usage for android.media AudioManager ROUTE_EARPIECE

List of usage examples for android.media AudioManager ROUTE_EARPIECE

Introduction

In this page you can find the example usage for android.media AudioManager ROUTE_EARPIECE.

Prototype

int ROUTE_EARPIECE

To view the source code for android.media AudioManager ROUTE_EARPIECE.

Click Source Link

Document

Routing audio output to earpiece

Usage

From source file:com.phonegap.AudioHandler.java

/**
 * Set the audio device to be used for playback.
 * /*  w  w  w.j  a v a  2  s . c o m*/
 * @param output         1=earpiece, 2=speaker
 */
public void setAudioOutputDevice(int output) {
    AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
    if (output == 2) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
    } else if (output == 1) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
    } else {
        System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
    }
}

From source file:com.phonegap.AudioHandler.java

/**
 * Get the audio device to be used for playback.
 * //from w  ww .  j av  a2 s  .com
 * @return               1=earpiece, 2=speaker
 */
public int getAudioOutputDevice() {
    AudioManager audiMgr = (AudioManager) this.ctx.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;
    }
}

From source file:org.skt.runtime.additionalapis.AudioHandler.java

/**
 * Set the audio device to be used for playback.
 *
 * @param output         1=earpiece, 2=speaker
 *//*ww w .ja v a 2 s  .  co  m*/
@SuppressWarnings("deprecation")
public void setAudioOutputDevice(int output) {
    AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
    if (output == 2) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
    } else if (output == 1) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
    } else {
        System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
    }
}

From source file:org.skt.runtime.additionalapis.AudioHandler.java

/**
 * Get the audio device to be used for playback.
 *
 * @return               1=earpiece, 2=speaker
 *//*  w w w.j ava 2  s.c om*/
@SuppressWarnings("deprecation")
public int getAudioOutputDevice() {
    AudioManager audiMgr = (AudioManager) this.ctx.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;
    }
}

From source file:com.commontime.cordova.audio.AudioHandler.java

/**
 * Set the audio device to be used for playback.
 *
 * @param output         1=earpiece, 2=speaker
 *///from   ww w .ja v a 2  s.  c  o m
@SuppressWarnings("deprecation")
public void setAudioOutputDevice(int output) {
    AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
    if (output == 2) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
    } else if (output == 1) {
        audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
    } else {
        System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
    }
}

From source file:com.commontime.cordova.audio.AudioHandler.java

/**
 * Get the audio device to be used for playback.
 *
 * @return               1=earpiece, 2=speaker
 *//*from w w  w. ja va2 s.c  o  m*/
@SuppressWarnings("deprecation")
public int getAudioOutputDevice() {
    AudioManager audiMgr = (AudioManager) this.cordova.getActivity().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;
    }
}