Search in sources :

Example 1 with EMServiceNotReadyException

use of com.easemob.exceptions.EMServiceNotReadyException in project wechat by motianhuo.

the class VoiceCallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_voice_call);
    comingBtnContainer = (LinearLayout) findViewById(R.id.ll_coming_call);
    refuseBtn = (Button) findViewById(R.id.btn_refuse_call);
    answerBtn = (Button) findViewById(R.id.btn_answer_call);
    hangupBtn = (Button) findViewById(R.id.btn_hangup_call);
    muteImage = (ImageView) findViewById(R.id.iv_mute);
    handsFreeImage = (ImageView) findViewById(R.id.iv_handsfree);
    callStateTextView = (TextView) findViewById(R.id.tv_call_state);
    nickTextView = (TextView) findViewById(R.id.tv_nick);
    durationTextView = (TextView) findViewById(R.id.tv_calling_duration);
    chronometer = (Chronometer) findViewById(R.id.chronometer);
    voiceContronlLayout = (LinearLayout) findViewById(R.id.ll_voice_control);
    refuseBtn.setOnClickListener(this);
    answerBtn.setOnClickListener(this);
    hangupBtn.setOnClickListener(this);
    muteImage.setOnClickListener(this);
    handsFreeImage.setOnClickListener(this);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    // 注册语音电话的状态的监听
    addCallStateListener();
    msgid = UUID.randomUUID().toString();
    username = getIntent().getStringExtra("username");
    // 语音电话是否为接收的
    isInComingCall = getIntent().getBooleanExtra("isComingCall", false);
    // 设置通话人
    nickTextView.setText(username);
    if (!isInComingCall) {
        // 拨打电话
        soundPool = new SoundPool(1, AudioManager.STREAM_RING, 0);
        outgoing = soundPool.load(this, R.raw.outgoing, 1);
        comingBtnContainer.setVisibility(View.INVISIBLE);
        hangupBtn.setVisibility(View.VISIBLE);
        st1 = getResources().getString(R.string.Are_connected_to_each_other);
        callStateTextView.setText(st1);
        handler.postDelayed(new Runnable() {

            public void run() {
                streamID = playMakeCallSounds();
            }
        }, 300);
        try {
            // 拨打语音电话
            EMChatManager.getInstance().makeVoiceCall(username);
        } catch (EMServiceNotReadyException e) {
            e.printStackTrace();
            final String st2 = getResources().getString(R.string.Is_not_yet_connected_to_the_server);
            runOnUiThread(new Runnable() {

                public void run() {
                    Toast.makeText(VoiceCallActivity.this, st2, 0).show();
                }
            });
        }
    } else {
        // 有电话进来
        voiceContronlLayout.setVisibility(View.INVISIBLE);
        Uri ringUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        audioManager.setMode(AudioManager.MODE_RINGTONE);
        audioManager.setSpeakerphoneOn(true);
        ringtone = RingtoneManager.getRingtone(this, ringUri);
        ringtone.play();
    }
}
Also used : EMServiceNotReadyException(com.easemob.exceptions.EMServiceNotReadyException) SoundPool(android.media.SoundPool) Uri(android.net.Uri)

Aggregations

SoundPool (android.media.SoundPool)1 Uri (android.net.Uri)1 EMServiceNotReadyException (com.easemob.exceptions.EMServiceNotReadyException)1