Example usage for android.media AudioManager MODE_IN_COMMUNICATION

List of usage examples for android.media AudioManager MODE_IN_COMMUNICATION

Introduction

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

Prototype

int MODE_IN_COMMUNICATION

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

Click Source Link

Document

In communication audio mode.

Usage

From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java

public static void onActivityDestroy(Context context) {
    BDebug.i(tag, "onActivityDestroy");
    AudioManager audioManager = (AudioManager) context.getApplicationContext()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION
            || audioManager.getMode() == AudioManager.MODE_IN_CALL) {
        audioManager.setMode(AudioManager.MODE_NORMAL);
    }/*from w  w w .j  a v  a 2  s.  c  om*/
}

From source file:org.linphone.compatibility.ApiElevenPlus.java

public static void setAudioManagerInCallMode(AudioManager manager) {
    if (manager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
        Log.w("---AudioManager: already in MODE_IN_COMMUNICATION, skipping...");
        return;//  w w  w  .j a v a2s.co  m
    }
    Log.d("---AudioManager: set mode to MODE_IN_COMMUNICATION");
    manager.setMode(AudioManager.MODE_IN_COMMUNICATION);
}

From source file:org.mitre.svmp.events.WebrtcHandler.java

public WebrtcHandler(BaseServer baseServer, VideoStreamInfo vidInfo, Context c) {
    base = baseServer;//  w ww.j  a v a  2  s .c om
    context = c;
    // Pass in context to allow access to Android managed Audio driver.
    PeerConnectionFactory.initializeAndroidGlobals(context);
    //        "Failed to initializeAndroidGlobals");

    AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn();
    audioManager.setMode(isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(!isWiredHeadsetOn);

    sdpMediaConstraints = new MediaConstraints();
    sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));

    pcConstraints = constraintsFromJSON(vidInfo.getPcConstraints());
    Log.d(TAG, "pcConstraints: " + pcConstraints);

    videoConstraints = constraintsFromJSON(vidInfo.getVideoConstraints());
    Log.d(TAG, "videoConstraints: " + videoConstraints);
    //        
    //        videoConstraints = new MediaConstraints();
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minWidth","720"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minHeight","1280"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth","720"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight","1280"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minFrameRate","24"));

    audioConstraints = new MediaConstraints(); //null;
    audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("audio", "true"));

    iceServers = iceServersFromPCConfigJSON(vidInfo.getIceServers());
    onIceServers(iceServers);
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

@SuppressWarnings("deprecation")
private JSONObject getAudioState(Context c) throws JSONException {
    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    JSONObject data = new JSONObject();

    data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn());
    data.put("is_microphone_mute", am.isMicrophoneMute());
    data.put("is_music_active", am.isMusicActive());
    data.put("is_speaker_phone_on", am.isSpeakerphoneOn());
    data.put("is_wired_headset_on", am.isWiredHeadsetOn());

    switch (am.getMode()) {
    case AudioManager.MODE_IN_CALL:
        data.put("mode", "in_call");
        break;/*from  ww  w  .  j av a 2  s  .co m*/
    case AudioManager.MODE_IN_COMMUNICATION:
        data.put("mode", "in_comm");
        break;
    case AudioManager.MODE_NORMAL:
        data.put("mode", "normal");
        break;
    case AudioManager.MODE_RINGTONE:
        data.put("mode", "ringtone");
        break;
    case AudioManager.MODE_INVALID:
    default:
        data.put("mode", "invalid");
        break;
    }

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        data.put("ringer_mode", "vibrate");
        break;
    case AudioManager.RINGER_MODE_SILENT:
        data.put("ringer_mode", "silent");
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        data.put("ringer_mode", "normal");
        break;
    default:
        data.put("ringer_mode", "invalid");
        break;
    }
    return data;
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // assume that the user cancels the call if it is ringing
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (!canCallBeResumed()) {
            if (null != mCall) {
                mCall.hangup("");
            }/*  ww  w .  java  2 s. c  om*/
        } else {
            saveCallView();
        }
    } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        // this is a trick to reduce the ring volume :
        // when the call is ringing, the AudioManager.Mode switch to MODE_IN_COMMUNICATION
        // so the volume is the next call one whereas the user expects to reduce the ring volume.
        if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_RINGING)) {
            AudioManager audioManager = (AudioManager) CallViewActivity.this
                    .getSystemService(Context.AUDIO_SERVICE);
            // IMXChrome call issue
            if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
                int musicVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
                        * audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
                        / audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVol, 0);
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}

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

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

    if (audioIcons != null)
        audioIcons.release();//from   w  w w.j a v a  2s.  c  o 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.digium.respokesdk.RespokeCall.java

private void addLocalStreams(Context context) {
    AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    // TODO(fischman): figure out how to do this Right(tm) and remove the suppression.
    @SuppressWarnings("deprecation")
    boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn();
    audioManager.setMode(isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(!isWiredHeadsetOn);

    localStream = peerConnectionFactory.createLocalMediaStream("ARDAMS");

    if (!audioOnly) {
        VideoCapturer capturer = getVideoCapturer();
        MediaConstraints videoConstraints = new MediaConstraints();
        videoSource = peerConnectionFactory.createVideoSource(capturer, videoConstraints);
        VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("ARDAMSv0", videoSource);
        videoTrack.addRenderer(new VideoRenderer(localRender));
        localStream.addTrack(videoTrack);
    }//from  w w w  . j ava2 s .c o m

    localStream.addTrack(peerConnectionFactory.createAudioTrack("ARDAMSa0",
            peerConnectionFactory.createAudioSource(new MediaConstraints())));

    peerConnection.addStream(localStream);
}

From source file:cx.ring.service.LocalService.java

private void updateAudioState() {
    boolean current = false;
    Conference ringing = null;/*www.  ja  v a  2 s.  c  o  m*/
    for (Conversation c : conversations.values()) {
        Conference conf = c.getCurrentCall();
        if (conf != null) {
            current = true;
            if (conf.isRinging()) {
                ringing = conf;
                break;
            }
        }
    }
    if (current)
        mediaManager.obtainAudioFocus(ringing != null);

    if (ringing != null) {
        //Log.w(TAG, "updateAudioState Ringing ");
        mediaManager.audioManager.setMode(AudioManager.MODE_RINGTONE);
        mediaManager.startRing(null);
    } else if (current) {
        //Log.w(TAG, "updateAudioState communication ");
        mediaManager.stopRing();
        mediaManager.audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    } else {
        //Log.w(TAG, "updateAudioState normal ");
        mediaManager.stopRing();
        mediaManager.abandonAudioFocus();
    }
}

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

private void configureDeviceForCall() {
    needPlayEndSound = true;//from w  w w  .  j  a va 2 s .co  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);
    }
}