Example usage for android.media AudioManager ROUTE_SPEAKER

List of usage examples for android.media AudioManager ROUTE_SPEAKER

Introduction

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

Prototype

int ROUTE_SPEAKER

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

Click Source Link

Document

Routing audio output to speaker

Usage

From source file:com.phonegap.AudioHandler.java

/**
 * Set the audio device to be used for playback.
 * /*from   ww  w .  ja  v  a2 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  .  jav  a 2  s  .co  m*/
 * @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
 *//*from ww w.  j a v  a2 s .  c  o  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  a  va  2 s.c o  m
@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
 *//* w ww.  j  ava 2 s.co 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
 *//*  ww w  . j  a v  a 2s. co 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;
    }
}