Exemplo n.º 1
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   if (cameraHelper != null) {
     cameraHelper.stopCapture();
     cameraHelper = null;
   }
   callHelper.setSurfaceView(null);
   if (isGoing) {
     isGoing = false;
     EMChatManager.getInstance().endCall();
   }
   if (callReceiver != null) {
     unregisterReceiver(callReceiver);
   }
 }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_watch);
    ButterKnife.bind(this);

    getWindow()
        .addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON // 保持屏幕常亮
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD // 关闭键盘
            );

    // 退出登录并使用username_uuid登录,记着拼接下划线(LoginUtil.USERNAME_EYE_DEPART)
    LoginUtil.relogin(
        AppConfig.getUsername() + LoginUtil.USERNAME_EYE_DEPART + CommonUtil.getUUID(this),
        new EMCallBack() {
          @Override
          public void onSuccess() {
            LogUtil.e("xmh-login", "eye");
            initAfterLogin();
          }

          @Override
          public void onError(int i, String s) {
            // do nothing
          }

          @Override
          public void onProgress(int i, String s) {
            // do nothing
          }
        });

    callHelper = EMVideoCallHelper.getInstance();
    LogUtil.e("xmh-record", "helper-create");
    cameraHelper = new CameraHelper(this, callHelper, surface.getHolder());

    callHelper.setSurfaceView(null);
    surface.getHolder().addCallback(new LocalCallback());

    // 设置视频状态监听
    setCallStateListener();
    setConnectionListener();
    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_RINGTONE);
    audioManager.setSpeakerphoneOn(true);

    // 监听结束通话广播
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(
            new BroadcastReceiver() {
              @Override
              public void onReceive(Context context, Intent intent) {
                if (isGoing) {
                  // 结束通话
                  EMChatManager.getInstance().endCall();
                  cameraHelper.setStartFlag(false);
                  isGoing = false;
                  LogUtil.e("xmh-record", "end call", true);
                }
              }
            },
            new IntentFilter(CommendUtil.ACTION_END_CALL));
  }