Example usage for android.media AudioManager MODE_NORMAL

List of usage examples for android.media AudioManager MODE_NORMAL

Introduction

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

Prototype

int MODE_NORMAL

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

Click Source Link

Document

Normal audio mode: not ringing and no call established.

Usage

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

/**
 * Set the audio device to be used for playback.
 *
 * @param output         1=earpiece, 2=speaker
 *///  w w w .j ava 2s .  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
 *///from  w  w  w.  jav a  2 s  .  co 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.mindprotectionkit.freephone.RedPhoneService.java

private void shutdownAudio() {
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_NORMAL);
}

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

/**
 * Set the audio device to be used for playback.
 *
 * @param output         1=earpiece, 2=speaker
 *//*www.ja  v a2  s .  c om*/
@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  ww w. j av  a  2s. 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;
    }
}

From source file:com.sourceauditor.sahomemonitor.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    } else if (id == R.id.action_display_reg) {
        showRegistrationId();/*from   www . j a v  a 2s.co  m*/
        return true;
    } else if (id == R.id.action_show_last_home_message) {
        showLastHomeMessage();
        return true;
    } else if (id == R.id.action_speaker) {
        if (audioManager.isSpeakerphoneOn()) {
            audioManager.setMode(AudioManager.MODE_NORMAL);
            audioManager.setSpeakerphoneOn(false);
            item.setChecked(false);
        } else {
            audioManager.setMode(AudioManager.MODE_NORMAL);
            audioManager.setSpeakerphoneOn(true);
            item.setChecked(true);
        }

    } else if (id == R.id.action_show_home_monitor_url) {
        showUrl();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:dk.bearware.gui.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (audioIcons != null)
        audioIcons.release();//from  w  ww . j av a  2s.  co  m
    sounds.clear();

    audioIcons = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    audioManager.setMode(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_VOICEPROCESSING, false)
            ? AudioManager.MODE_IN_COMMUNICATION
            : AudioManager.MODE_NORMAL);
    audioManager.setSpeakerphoneOn(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_SPEAKERPHONE, false));

    if (prefs.getBoolean("server_lost_audio_icon", true)) {
        sounds.put(SOUND_SERVERLOST, audioIcons.load(getApplicationContext(), R.raw.serverlost, 1));
    }
    if (prefs.getBoolean("rx_tx_audio_icon", true)) {
        sounds.put(SOUND_VOICETXON, audioIcons.load(getApplicationContext(), R.raw.on, 1));
        sounds.put(SOUND_VOICETXOFF, audioIcons.load(getApplicationContext(), R.raw.off, 1));
    }
    if (prefs.getBoolean("personal_message_audio_icon", true)) {
        sounds.put(SOUND_USERMSG, audioIcons.load(getApplicationContext(), R.raw.user_message, 1));
    }
    if (prefs.getBoolean("channel_message_audio_icon", true)) {
        sounds.put(SOUND_CHANMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1));
    }
    if (prefs.getBoolean("broadcast_message_audio_icon", true)) {
        sounds.put(SOUND_BCASTMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1));
    }
    if (prefs.getBoolean("files_updated_audio_icon", true)) {
        sounds.put(SOUND_FILESUPDATE, audioIcons.load(getApplicationContext(), R.raw.fileupdate, 1));
    }
    if (prefs.getBoolean("voiceact_triggered_icon", true)) {
        sounds.put(SOUND_VOXON, audioIcons.load(getApplicationContext(), R.raw.voiceact_on, 1));
        sounds.put(SOUND_VOXOFF, audioIcons.load(getApplicationContext(), R.raw.voiceact_off, 1));
    }
    if (prefs.getBoolean("transmitready_icon", true)) {
        sounds.put(SOUND_TXREADY, audioIcons.load(getApplicationContext(), R.raw.txqueue_start, 1));
        sounds.put(SOUND_TXSTOP, audioIcons.load(getApplicationContext(), R.raw.txqueue_stop, 1));
    }
    if (prefs.getBoolean("userjoin_icon", true)) {
        sounds.put(SOUND_USERJOIN, audioIcons.load(getApplicationContext(), R.raw.user_join, 1));
    }
    if (prefs.getBoolean("userleft_icon", true)) {
        sounds.put(SOUND_USERLEFT, audioIcons.load(getApplicationContext(), R.raw.user_left, 1));
    }

    getTextMessagesAdapter().showLogMessages(prefs.getBoolean("show_log_messages", true));

    getWindow().getDecorView().setKeepScreenOn(prefs.getBoolean("keep_screen_on_checkbox", false));

    createStatusTimer();
}

From source file:com.ferdi2005.secondgram.voip.VoIPService.java

@Override
public void onDestroy() {
    FileLog.d("=============== VoIPService STOPPING ===============");
    stopForeground(true);//from  w ww .j  a v a 2 s  .c om
    stopRinging();
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout);
    SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximity != null) {
        sm.unregisterListener(this);
    }
    if (proximityWakelock != null && proximityWakelock.isHeld()) {
        proximityWakelock.release();
    }
    unregisterReceiver(receiver);
    if (timeoutRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(timeoutRunnable);
        timeoutRunnable = null;
    }
    super.onDestroy();
    sharedInstance = null;
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance().postNotificationName(NotificationCenter.didEndedCall);
        }
    });
    if (controller != null && controllerStarted) {
        lastKnownDuration = controller.getCallDuration();
        updateStats();
        StatsController.getInstance().incrementTotalCallsTime(getStatsNetworkType(),
                (int) (lastKnownDuration / 1000) % 5);
        if (needSendDebugLog) {
            String debugLog = controller.getDebugLog();
            TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
            req.debug = new TLRPC.TL_dataJSON();
            req.debug.data = debugLog;
            req.peer = new TLRPC.TL_inputPhoneCall();
            req.peer.access_hash = call.access_hash;
            req.peer.id = call.id;
            ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                @Override
                public void run(TLObject response, TLRPC.TL_error error) {
                    FileLog.d("Sent debug logs, response=" + response);
                }
            });
        }
        controller.release();
        controller = null;
    }
    cpuWakelock.release();
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (isBtHeadsetConnected && !playingSound)
        am.stopBluetoothSco();
    am.setMode(AudioManager.MODE_NORMAL);
    am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));
    if (haveAudioFocus)
        am.abandonAudioFocus(this);

    if (!playingSound)
        soundPool.release();

    ConnectionsManager.getInstance().setAppPaused(true, false);
}

From source file:com.brejza.matt.habmodem.Dsp_service.java

public void disableEcho() {
    AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    manager.setMode(AudioManager.MODE_NORMAL);
    manager.setSpeakerphoneOn(false);/*  ww  w. j a  v a  2  s  .c o  m*/
    enableEcho = false;
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

public static void playbackFile(final Activity context, final FileMirakel file, final boolean loud) {
    final MediaPlayer mPlayer = new MediaPlayer();
    final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (!loud) {/*from w w  w.  ja v a2  s.  c  om*/
        am.setSpeakerphoneOn(false);
        am.setMode(AudioManager.MODE_IN_CALL);
        context.setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
    }
    try {
        mPlayer.reset();
        if (!loud) {
            mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
        }
        mPlayer.setDataSource(file.getFileStream(context).getFD());
        mPlayer.prepare();
        mPlayer.start();
        mPlayer.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(final MediaPlayer mp) {
                audio_playback_dialog.dismiss();
            }
        });
        am.setMode(AudioManager.MODE_NORMAL);
        audio_playback_playing = true;
    } catch (final IOException e) {
        Log.e(TAG, "prepare() failed");
    }
    audio_playback_dialog = new AlertDialog.Builder(context).setTitle(R.string.audio_playback_title)
            .setPositiveButton(R.string.audio_playback_pause, null)
            .setNegativeButton(R.string.audio_playback_stop, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    mPlayer.release();
                }
            }).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(final DialogInterface dialog) {
                    mPlayer.release();
                    dialog.cancel();
                }
            }).create();
    audio_playback_dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            final Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    if (audio_playback_playing) {
                        button.setText(R.string.audio_playback_play);
                        mPlayer.pause();
                        audio_playback_playing = false;
                    } else {
                        button.setText(R.string.audio_playback_pause);
                        mPlayer.start();
                        audio_playback_playing = true;
                    }
                }
            });
        }
    });
    audio_playback_dialog.show();
}