Example usage for android.media AudioManager STREAM_VOICE_CALL

List of usage examples for android.media AudioManager STREAM_VOICE_CALL

Introduction

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

Prototype

int STREAM_VOICE_CALL

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

Click Source Link

Document

Used to identify the volume of audio streams for phone calls

Usage

From source file:com.telestax.restcomm_olympus.CallActivity.java

public void onConnected(RCConnection connection, HashMap<String, String> customHeaders) {
    Log.i(TAG, "RCConnection connected, customHeaders: " + customHeaders);
    lblStatus.setText("Connected");

    btnMuteAudio.setVisibility(View.VISIBLE);
    btnMuteVideo.setVisibility(View.VISIBLE);
    btnKeypad.setVisibility(View.VISIBLE);

    lblTimer.setVisibility(View.VISIBLE);
    startTimer();//w w w.j ava 2 s. c om

    // reset to no mute at beggining of new call
    muteAudio = false;
    muteVideo = false;

    setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}

From source file:de.dfki.iui.mmir.plugins.speech.android.AndroidSpeechRecognizer.java

void disableSoundFeedback() {

    if (!mIsStreamSolo && isDisableSoundPrompt()) {

        if (delayedEnableSoundHandler != null) {
            delayedEnableSoundHandler.cancel();
            delayedEnableSoundHandler = null;
        }/*from w  ww .  j av a 2  s.c  om*/

        mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
        mIsStreamSolo = true;

        Log.e(PLUGIN_NAME + "_debug-solostream", "DISABLE SOUND -> solo-counter: " + (++soloCounter));
    }
}

From source file:de.dfki.iui.mmir.plugins.speech.android.AndroidSpeechRecognizer.java

void enableSoundFeedback() {

    if (mIsStreamSolo) {
        mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
        mIsStreamSolo = false;/*  w  ww . j  a  v  a2 s  . co  m*/

        Log.e(PLUGIN_NAME + "_debug-solostream", "ENABLE SOUND -> solo-counter: " + (--soloCounter));
    }
}

From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java

private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_RING");

    if ("STREAM_VOICE_CALL".equals(value)) {
        return AudioManager.STREAM_VOICE_CALL;
    } else if ("STREAM_SYSTEM".equals(value)) {
        return AudioManager.STREAM_SYSTEM;
    } else if ("STREAM_RING".equals(value)) {
        return AudioManager.STREAM_RING;
    } else if ("STREAM_MUSIC".equals(value)) {
        return AudioManager.STREAM_MUSIC;
    } else if ("STREAM_ALARM".equals(value)) {
        return AudioManager.STREAM_ALARM;
    } else if ("STREAM_NOTIFICATION".equals(value)) {
        return AudioManager.STREAM_NOTIFICATION;
    } else if ("STREAM_DTMF".equals(value)) {
        return AudioManager.STREAM_DTMF;
    } else {//from  w  w  w  .j a  v a  2 s  .c om
        return AudioManager.STREAM_RING;
    }
}

From source file:im.vector.activity.CallViewActivity.java

/**
 * Init the buttons layer/* w ww. j  a  v a  2  s  . co  m*/
 */
private void manageSubViews() {
    // sanity check
    // the call could have been destroyed between call.
    if (null == mCall) {
        Log.d(LOG_TAG, "manageSubViews nothing to do");
        return;
    }

    // initialize buttons
    if (null == mAcceptRejectLayout) {
        mAcceptRejectLayout = findViewById(R.id.layout_accept_reject);
        mAcceptButton = (Button) findViewById(R.id.accept_button);
        mRejectButton = (Button) findViewById(R.id.reject_button);
        mCancelButton = (Button) findViewById(R.id.cancel_button);
        mStopButton = (Button) findViewById(R.id.stop_button);
        mSpeakerSelectionView = (ImageView) findViewById(R.id.call_speaker_view);

        mCallStateTextView = (TextView) findViewById(R.id.call_state_text);

        mAcceptButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mCall) {
                    mCall.answer();
                }
            }
        });

        mRejectButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onHangUp();
            }
        });

        mCancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onHangUp();
            }
        });

        mStopButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onHangUp();
            }
        });

        mSpeakerSelectionView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mCall) {
                    mCall.toggleSpeaker();
                    refreshSpeakerButton();
                }
            }
        });

        updateStateTextView("", false);
    }

    String callState = mCall.getCallState();

    Log.d(LOG_TAG, "manageSubViews callState : " + callState);

    // hide / show avatar
    ImageView avatarView = (ImageView) CallViewActivity.this.findViewById(R.id.call_other_member);
    if (null != avatarView) {
        avatarView.setVisibility(
                (callState.equals(IMXCall.CALL_STATE_CONNECTED) && mCall.isVideo()) ? View.GONE : View.VISIBLE);
    }

    refreshSpeakerButton();

    // display the button according to the call state
    if (callState.equals(IMXCall.CALL_STATE_ENDED)) {
        mAcceptRejectLayout.setVisibility(View.GONE);
        mCancelButton.setVisibility(View.GONE);
        mStopButton.setVisibility(View.GONE);
    } else if (callState.equals(IMXCall.CALL_STATE_CONNECTED)) {
        mAcceptRejectLayout.setVisibility(View.GONE);
        mCancelButton.setVisibility(View.GONE);
        mStopButton.setVisibility(View.VISIBLE);
    } else {
        mAcceptRejectLayout.setVisibility(mCall.isIncoming() ? View.VISIBLE : View.GONE);
        mCancelButton.setVisibility(mCall.isIncoming() ? View.GONE : View.VISIBLE);
        mStopButton.setVisibility(View.GONE);
    }

    // display the callview only when the preview is displayed
    if (mCall.isVideo() && !callState.equals(IMXCall.CALL_STATE_ENDED)) {
        int visibility;

        if (callState.equals(IMXCall.CALL_STATE_WAIT_CREATE_OFFER)
                || callState.equals(IMXCall.CALL_STATE_INVITE_SENT)
                || callState.equals(IMXCall.CALL_STATE_RINGING)
                || callState.equals(IMXCall.CALL_STATE_CREATE_ANSWER)
                || callState.equals(IMXCall.CALL_STATE_CONNECTING)
                || callState.equals(IMXCall.CALL_STATE_CONNECTED)) {
            visibility = View.VISIBLE;
        } else {
            visibility = View.GONE;
        }

        if ((null != mCall) && (visibility != mCall.getVisibility())) {
            mCall.setVisibility(visibility);
        }
    }

    // display the callstate
    if (callState.equals(IMXCall.CALL_STATE_CONNECTING) || callState.equals(IMXCall.CALL_STATE_CREATE_ANSWER)
            || callState.equals(IMXCall.CALL_STATE_WAIT_LOCAL_MEDIA)
            || callState.equals(IMXCall.CALL_STATE_WAIT_CREATE_OFFER)) {
        mAcceptButton.setAlpha(0.5f);
        mAcceptButton.setEnabled(false);
        updateStateTextView(getResources().getString(R.string.call_connecting), true);
        mCallStateTextView.setVisibility(View.VISIBLE);
        stopRinging();
    } else if (callState.equals(IMXCall.CALL_STATE_CONNECTED)) {
        stopRinging();

        CallViewActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AudioManager audioManager = (AudioManager) CallViewActivity.this
                        .getSystemService(Context.AUDIO_SERVICE);
                audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, mCallVolume, 0);
                MXCallsManager.setSpeakerphoneOn(CallViewActivity.this, mCall.isVideo());
                refreshSpeakerButton();
            }
        });

        updateStateTextView(getResources().getString(R.string.call_connected), false);
        mCallStateTextView.setVisibility(mCall.isVideo() ? View.GONE : View.VISIBLE);
    } else if (callState.equals(IMXCall.CALL_STATE_ENDED)) {
        updateStateTextView(getResources().getString(R.string.call_ended), true);
        mCallStateTextView.setVisibility(View.VISIBLE);
    } else if (callState.equals(IMXCall.CALL_STATE_RINGING)) {
        if (mCall.isIncoming()) {
            if (mCall.isVideo()) {
                updateStateTextView(getResources().getString(R.string.incoming_video_call), true);
            } else {
                updateStateTextView(getResources().getString(R.string.incoming_voice_call), true);
            }
        } else {
            updateStateTextView(getResources().getString(R.string.call_ring), true);
        }
        mCallStateTextView.setVisibility(View.VISIBLE);

        if (mAutoAccept) {
            mAutoAccept = false;
            mAcceptButton.setAlpha(0.5f);
            mAcceptButton.setEnabled(false);
            mCallStateTextView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mCall.answer();
                }
            }, 100);
        } else {
            mAcceptButton.setAlpha(1.0f);
            mAcceptButton.setEnabled(true);

            if (mCall.isIncoming()) {
                startRinging(CallViewActivity.this);
            } else {
                startRingbackSound(CallViewActivity.this);
            }
        }
    }
}

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  .j a  v a 2 s. c o  m*/
        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();
}

From source file:im.vector.activity.CallViewActivity.java

private void setMediaPlayerVolume(int percent) {
    if (percent < 0 || percent > 100) {
        Log.e(LOG_TAG, "setMediaPlayerVolume percent is invalid: " + percent);
        return;//from www  .  ja  v  a2  s  . c om
    }

    AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    mCallVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);

    int maxMusicVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int maxVoiceVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);

    if (maxMusicVol > 0) {
        int volume = (int) ((float) percent / 100f * maxMusicVol);
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);

        volume = (int) ((float) percent / 100f * maxVoiceVol);
        audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0);
    }
    Log.i(LOG_TAG,
            "Set media volume (ringback) to: " + audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
}

From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (Settings.PREF_THEME.equals(key)) {
        // Recreate activity when theme is changed
        if (Build.VERSION.SDK_INT >= 11)
            recreate();/* w  ww  .  j  a va  2  s . c om*/
        else {
            Intent intent = new Intent(this, PlumbleActivity.class);
            finish();
            startActivity(intent);
        }
    } else if (Settings.PREF_STAY_AWAKE.equals(key)) {
        setStayAwake(mSettings.shouldStayAwake());
    } else if (Settings.PREF_HANDSET_MODE.equals(key)) {
        setVolumeControlStream(
                mSettings.isHandsetMode() ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);
    }
}

From source file:org.restcomm.android.olympus.CallActivity.java

public void onConnected(RCConnection connection, HashMap<String, String> customHeaders) {
    Log.i(TAG, "RCConnection connected, customHeaders: " + customHeaders);
    lblStatus.setText("Connected");

    btnMuteAudio.setVisibility(View.VISIBLE);
    if (!isVideo) {
        btnMuteVideo.setEnabled(false);/*  ww w.  j  a  v a2  s.  c  o m*/
        btnMuteVideo.setColorFilter(Color.parseColor(getString(R.string.string_color_filter_video_disabled)));
    }
    btnMuteVideo.setVisibility(View.VISIBLE);
    btnKeypad.setVisibility(View.VISIBLE);

    lblTimer.setVisibility(View.VISIBLE);

    // Save time we got connected in case the call is paused and we need to resume it
    SharedPreferences.Editor editor = prefs.edit();
    editor.putLong(LIVE_CALL_PAUSE_TIME, System.currentTimeMillis());
    editor.apply();

    startTimer(0);

    // reset to no mute at beggining of new call
    muteAudio = false;
    muteVideo = false;

    setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}

From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java

@SuppressWarnings("deprecation")
public boolean disconnect() {
    disconnect = true;/*from ww  w  .ja  v a  2 s.c om*/
    connected = false;

    if (ttsActive && !muted && prefs.getBoolean("tts_disconnect", true)) {
        HashMap<String, String> params = new HashMap<String, String>();
        if (am.isBluetoothScoOn())
            params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Disconnected");
        tts.speak("Disconnected.", TextToSpeech.QUEUE_ADD, params);
        tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
            @Override
            public void onUtteranceCompleted(String utteranceId) {
                if (utteranceId.equals("Disconnected")) {
                    tts.shutdown();

                    stopForeground(true);
                    stopSelf();
                }
            }
        });
    } else if (ringtoneActive && !muted) {
        ringtone = RingtoneManager.getRingtone(VentriloidService.this,
                Uri.parse(prefs.getString("disconnect_notification",
                        RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString())));
        ringtone.play();

        stopForeground(true);
        stopSelf();
    } else {
        stopForeground(true);
        stopSelf();
    }

    return true;
}