Java Code Examples for android.media.AudioManager#MODE_IN_COMMUNICATION

The following examples show how to use android.media.AudioManager#MODE_IN_COMMUNICATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RtcActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 免提,切换外放和听筒
 */
private void switchAudioMute() {
    int result = audioManager.ting();
    if(result == AudioManager.MODE_NORMAL) {
        if(videoEnable) {
            rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
        } else {
            audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
        }
    } else if(result == AudioManager.MODE_IN_COMMUNICATION) {
        if(videoEnable) {
            rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
        } else {
            audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
        }
    }

}
 
Example 2
Source File: WebRtcAudioManager.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public void run() {
  final int mode = audioManager.getMode();
  if (mode == AudioManager.MODE_RINGTONE) {
    Logging.d(TAG, "STREAM_RING stream volume: "
            + audioManager.getStreamVolume(AudioManager.STREAM_RING) + " (max="
            + maxRingVolume + ")");
  } else if (mode == AudioManager.MODE_IN_COMMUNICATION) {
    Logging.d(TAG, "VOICE_CALL stream volume: "
            + audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL) + " (max="
            + maxVoiceCallVolume + ")");
  }
}
 
Example 3
Source File: VolumeLogger.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public void run() {
  final int mode = audioManager.getMode();
  if (mode == AudioManager.MODE_RINGTONE) {
    Logging.d(TAG,
        "STREAM_RING stream volume: " + audioManager.getStreamVolume(AudioManager.STREAM_RING)
            + " (max=" + maxRingVolume + ")");
  } else if (mode == AudioManager.MODE_IN_COMMUNICATION) {
    Logging.d(TAG,
        "VOICE_CALL stream volume: "
            + audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
            + " (max=" + maxVoiceCallVolume + ")");
  }
}
 
Example 4
Source File: RtcActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
private void playAudio() {
        switch (audioManager.getRingMode()) {
            case AudioManager.RINGER_MODE_NORMAL://响铃
            case AudioManager.MODE_IN_COMMUNICATION://音频通话
                MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
                if(!isCaller) {
                    audioManager.changeToEarpieceMode();
                } else {
                    audioManager.changeToSpeakerMode();
                }
//                        MediaUtils.loadRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
//                        MediaUtils.playRtcTone(RtcActivity.this);
                break;
            case AudioManager.RINGER_MODE_SILENT://静音
            case AudioManager.RINGER_MODE_VIBRATE://震动
                if(!isCaller) {
                    MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
                    audioManager.changeToEarpieceMode();
                } else {
                    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
                    //按照指定的模式去震动。
//				vibrator.vibrate(1000);
                    //数组参数意义:第一个参数为等待指定时间后开始震动,震动时间为第二个参数。后边的参数依次为等待震动和震动的时间
                    //第二个参数为重复次数,-1为不重复,0为一直震动
                    vibrator.vibrate( new long[]{1000,1000},0);
                }
                break;
        }
    }
 
Example 5
Source File: RtcActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
protected void shownVideo() {
    //localRender.setVisibility(View.VISIBLE);
    //remoteRender.setVisibility(View.VISIBLE);
    //vsv.setVisibility(View.VISIBLE);
    videoLayout.setVisibility(View.VISIBLE);
    audioLayout.setVisibility(View.GONE);

    if(audioManager == null) return;
    if(audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
        rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
    } else {
        rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
    }
}
 
Example 6
Source File: RtcActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
protected void showAudio() {
    videoLayout.setVisibility(View.GONE);
    audioLayout.setVisibility(View.VISIBLE);
    if(audioManager == null) return;
    if(audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
        audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
    } else {
        audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
    }
}
 
Example 7
Source File: AppRTCAudioManager.java    From imsdk-android with MIT License 5 votes vote down vote up
public int ting()
{
   if(getSelectedAudioDevice() == AudioDevice.SPEAKER_PHONE)
   {
     if(audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION)
     {
       return changeToSpeakerMode();
     }
     else if(audioManager.getMode() == AudioManager.MODE_NORMAL) {
       return changeToEarpieceMode();
     }
   }
  return -1;
}
 
Example 8
Source File: AppRTCAudioManager.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 听筒模式
 * @return
 */
public int changeToEarpieceMode() {
  audioManager.setSpeakerphoneOn(false);
  audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
  ((Activity) apprtcContext).setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
  return AudioManager.MODE_IN_COMMUNICATION;
}
 
Example 9
Source File: CallActivity.java    From sealrtc-android with MIT License 5 votes vote down vote up
private void startBluetoothSco() {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (am != null) {
        if (am.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
            am.setMode(AudioManager.MODE_IN_COMMUNICATION);
        }
        am.setSpeakerphoneOn(false);
        am.startBluetoothSco();
    }
}
 
Example 10
Source File: LinphoneManager.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
public void setAudioManagerInCallMode() {
	if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
		Log.w("[AudioManager] already in MODE_IN_COMMUNICATION, skipping...");
		return;
	}
	Log.d("[AudioManager] Mode: MODE_IN_COMMUNICATION");
	mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
}
 
Example 11
Source File: CallViewActivity.java    From matrix-android-console with Apache License 2.0 5 votes vote down vote up
@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("");
            }
        } 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);
}
 
Example 12
Source File: AndroidAudioManager.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
private void setAudioManagerInCallMode() {
    if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
        Log.w("[Audio Manager] already in MODE_IN_COMMUNICATION, skipping...");
        return;
    }
    Log.d("[Audio Manager] Mode: MODE_IN_COMMUNICATION");

    mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
}
 
Example 13
Source File: AndroidAudioManager.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void routeAudioToBluetooth() {
    if (!isBluetoothHeadsetConnected()) {
        Log.w("[Audio Manager] [Bluetooth] No headset connected");
        return;
    }
    if (mAudioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
        Log.w(
                "[Audio Manager] [Bluetooth] Changing audio mode to MODE_IN_COMMUNICATION and requesting STREAM_VOICE_CALL focus");
        mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
        requestAudioFocus(STREAM_VOICE_CALL);
    }
    changeBluetoothSco(true);
}
 
Example 14
Source File: WebRtcAudioManager.java    From webrtc_android with MIT License 4 votes vote down vote up
private boolean isCommunicationModeEnabled() {
  return (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION);
}
 
Example 15
Source File: CallActivity.java    From sealrtc-android with MIT License 4 votes vote down vote up
@Override
public void onNotifyHeadsetState(boolean connected, int type) {
    try {
        if (connected) {
            HeadsetPlugReceiverState = true;
            if (type == 0) {
                startBluetoothSco();
            }
            if (null != btnMuteSpeaker) {
                btnMuteSpeaker.setBackgroundResource(R.drawable.img_capture_gray);
                btnMuteSpeaker.setSelected(false);
                btnMuteSpeaker.setEnabled(false);
                btnMuteSpeaker.setClickable(false);
                audioManager.onToggleSpeaker(false);
            }
        } else {
            if (type == 1 && BluetoothUtil.hasBluetoothA2dpConnected()) {
                return;
            }
            AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (am != null) {
                if (am.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
                    am.setMode(AudioManager.MODE_IN_COMMUNICATION);
                }
                if (type == 0) {
                    am.stopBluetoothSco();
                    am.setBluetoothScoOn(false);
                    am.setSpeakerphoneOn(!muteSpeaker);
                } else {
                    RCRTCEngine.getInstance().enableSpeaker(!this.muteSpeaker);
                }
                audioManager.onToggleSpeaker(!muteSpeaker);
            }
            if (null != btnMuteSpeaker) {
                btnMuteSpeaker.setBackgroundResource(R.drawable.selector_checkbox_capture);
                btnMuteSpeaker.setSelected(false);
                btnMuteSpeaker.setEnabled(true);
                btnMuteSpeaker.setClickable(true);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: Utils.java    From ForceDoze with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isUserInCommunicationCall(Context context) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return manager.getMode() == AudioManager.MODE_IN_CALL || manager.getMode() == AudioManager.MODE_IN_COMMUNICATION;
}