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.ferdi2005.secondgram.voip.VoIPService.java

private void configureDeviceForCall() {
    needPlayEndSound = true;// www.j a v  a2s  .  c  o  m
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_IN_COMMUNICATION);
    am.setSpeakerphoneOn(false);
    am.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);

    SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    try {
        if (proximity != null) {
            proximityWakelock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
                    .newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "telegram-voip-prx");
            sm.registerListener(this, proximity, SensorManager.SENSOR_DELAY_NORMAL);
        }
    } catch (Exception x) {
        FileLog.e("Error initializing proximity sensor", x);
    }
}

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

public boolean hasEarpiece() {
    if (((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
            .getPhoneType() != TelephonyManager.PHONE_TYPE_NONE)
        return true;
    if (mHasEarpiece != null) {
        return mHasEarpiece;
    }//  w  w w.  ja va 2 s .  c  om

    // not calculated yet, do it now
    try {
        AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
        Method method = AudioManager.class.getMethod("getDevicesForStream", Integer.TYPE);
        Field field = AudioManager.class.getField("DEVICE_OUT_EARPIECE");
        int earpieceFlag = field.getInt(null);
        int bitmaskResult = (int) method.invoke(am, AudioManager.STREAM_VOICE_CALL);

        // check if masked by the earpiece flag
        if ((bitmaskResult & earpieceFlag) == earpieceFlag) {
            mHasEarpiece = Boolean.TRUE;
        } else {
            mHasEarpiece = Boolean.FALSE;
        }
    } catch (Throwable error) {
        FileLog.e("Error while checking earpiece! ", error);
        mHasEarpiece = Boolean.TRUE;
    }

    return mHasEarpiece;
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

protected void muteAllSounds() {
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_ALARM, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_DTMF, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_MUSIC, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_RING, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_SYSTEM, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_VOICE_CALL, true);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0, 0);

    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_DTMF, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_MUTE, 0);
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

protected void unmuteAllSounds() {
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_ALARM, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_DTMF, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_MUSIC, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_RING, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_SYSTEM, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_VOICE_CALL, false);

    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

@Override
public void didReceivedNotification(int id, Object... args) {
    if (id == NotificationCenter.emojiDidLoaded) {
        if (emojiView != null) {
            emojiView.invalidateViews();
        }/*from ww w . j a va 2 s  . c  o m*/
        if (botKeyboardView != null) {
            botKeyboardView.invalidateViews();
        }
    } else if (id == NotificationCenter.recordProgressChanged) {
        long t = (Long) args[0];
        Long time = t / 1000;
        int ms = (int) (t % 1000L) / 10;
        String str = String.format("%02d:%02d.%02d", time / 60, time % 60, ms);
        if (lastTimeString == null || !lastTimeString.equals(str)) {
            if (time % 5 == 0) {
                MessagesController.getInstance().sendTyping(dialog_id, 1, 0);
            }
            if (recordTimeText != null) {
                recordTimeText.setText(str);
            }
        }
        if (recordCircle != null) {
            recordCircle.setAmplitude((Double) args[1]);
        }
    } else if (id == NotificationCenter.closeChats) {
        if (messageEditText != null && messageEditText.isFocused()) {
            AndroidUtilities.hideKeyboard(messageEditText);
        }
    } else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) {
        if (recordingAudioVideo) {
            MessagesController.getInstance().sendTyping(dialog_id, 2, 0);
            recordingAudioVideo = false;
            updateRecordIntefrace();
        }
    } else if (id == NotificationCenter.recordStarted) {
        if (!recordingAudioVideo) {
            recordingAudioVideo = true;
            updateRecordIntefrace();
        }
    } else if (id == NotificationCenter.audioDidSent) {
        audioToSend = (TLRPC.TL_document) args[0];
        audioToSendPath = (String) args[1];
        if (audioToSend != null) {
            if (recordedAudioPanel == null) {
                return;
            }

            TLRPC.TL_message message = new TLRPC.TL_message();
            message.out = true;
            message.id = 0;
            message.to_id = new TLRPC.TL_peerUser();
            message.to_id.user_id = message.from_id = UserConfig.getClientUserId();
            message.date = (int) (System.currentTimeMillis() / 1000);
            message.message = "-1";
            message.attachPath = audioToSendPath;
            message.media = new TLRPC.TL_messageMediaDocument();
            message.media.document = audioToSend;
            message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
            audioToSendMessageObject = new MessageObject(message, null, false);

            recordedAudioPanel.setAlpha(1.0f);
            recordedAudioPanel.setVisibility(VISIBLE);
            int duration = 0;
            for (int a = 0; a < audioToSend.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    duration = attribute.duration;
                    break;
                }
            }

            for (int a = 0; a < audioToSend.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.waveform == null || attribute.waveform.length == 0) {
                        attribute.waveform = MediaController.getInstance().getWaveform(audioToSendPath);
                    }
                    recordedAudioSeekBar.setWaveform(attribute.waveform);
                    break;
                }
            }
            recordedAudioTimeTextView.setText(String.format("%d:%02d", duration / 60, duration % 60));
            closeKeyboard();
            hidePopup(false);
            checkSendButton(false);
        } else {
            if (delegate != null) {
                delegate.onMessageSend(null);
            }
        }
    } else if (id == NotificationCenter.audioRouteChanged) {
        if (parentActivity != null) {
            boolean frontSpeaker = (Boolean) args[0];
            parentActivity.setVolumeControlStream(
                    frontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.USE_DEFAULT_STREAM_TYPE);
        }
    } else if (id == NotificationCenter.audioDidReset) {
        if (audioToSendMessageObject != null
                && !MediaController.getInstance().isPlayingAudio(audioToSendMessageObject)) {
            recordedAudioPlayButton.setImageDrawable(playDrawable);
            recordedAudioSeekBar.setProgress(0);
        }
    } else if (id == NotificationCenter.audioProgressDidChanged) {
        Integer mid = (Integer) args[0];
        if (audioToSendMessageObject != null
                && MediaController.getInstance().isPlayingAudio(audioToSendMessageObject)) {
            MessageObject player = MediaController.getInstance().getPlayingMessageObject();
            audioToSendMessageObject.audioProgress = player.audioProgress;
            audioToSendMessageObject.audioProgressSec = player.audioProgressSec;
            if (!recordedAudioSeekBar.isDragging()) {
                recordedAudioSeekBar.setProgress(audioToSendMessageObject.audioProgress);
            }
        }
    } else if (id == NotificationCenter.featuredStickersDidLoaded) {
        if (emojiButton != null) {
            emojiButton.invalidate();
        }
    }
}