示例#1
0
 /** 视频切换为音频 */
 public void onVideoToAudio() {
   // 判断是否静音,扬声器是否开启,对界面相应控件进行显隐处理。
   avChatAudio.onVideoToAudio(
       AVChatManager.getInstance().isMute(),
       AVChatManager.getInstance().speakerEnabled(),
       AVChatManager.getInstance().isRecording(),
       recordWarning);
 }
示例#2
0
  private void updateRecordTip() {

    if (CallStateEnum.isAudioMode(callingState)) {
      avChatAudio.showRecordView(AVChatManager.getInstance().isRecording(), recordWarning);
    }
    if (CallStateEnum.isVideoMode(callingState)) {
      avChatVideo.showRecordView(AVChatManager.getInstance().isRecording(), recordWarning);
    }
  }
示例#3
0
 public void resetRecordTip() {
   uiHandler.removeCallbacks(runnable);
   recordWarning = false;
   if (CallStateEnum.isAudioMode(callingState)) {
     avChatAudio.showRecordView(AVChatManager.getInstance().isRecording(), recordWarning);
   }
   if (CallStateEnum.isVideoMode(callingState)) {
     avChatVideo.showRecordView(AVChatManager.getInstance().isRecording(), recordWarning);
   }
 }
示例#4
0
  @Override
  public void toggleRecord() {
    if (AVChatManager.getInstance().isRecording()) {
      AVChatManager.getInstance()
          .stopRecord(
              new AVChatCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid) {}

                @Override
                public void onFailed(int code) {}

                @Override
                public void onException(Throwable exception) {}
              });

      uiHandler.removeCallbacks(runnable);
      recordWarning = false;

    } else {
      recordWarning = false;

      if (AVChatManager.getInstance()
          .startRecord(
              new AVChatCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid) {}

                @Override
                public void onFailed(int code) {}

                @Override
                public void onException(Throwable exception) {}
              })) {

        if (CallStateEnum.isAudioMode(callingState)) {
          Toast.makeText(context, "仅录制你说话的内容", Toast.LENGTH_SHORT).show();
        }

        if (CallStateEnum.isVideoMode(callingState)) {
          Toast.makeText(context, "仅录制你的声音和图像", Toast.LENGTH_SHORT).show();
        }

        uiHandler.post(runnable);

      } else {

        Toast.makeText(context, "录制失败", Toast.LENGTH_SHORT).show();
      }
    }

    updateRecordTip();
  }
示例#5
0
 /** 音频切换为视频 */
 public void onAudioToVideo() {
   onCallStateChange(CallStateEnum.VIDEO);
   avChatVideo.onAudioToVideo(
       AVChatManager.getInstance().isMute(),
       AVChatManager.getInstance().isRecording(),
       recordWarning); // isMute是否处于静音状态
   if (!AVChatManager.getInstance().isVideoSend()) { // 是否在发送视频 即摄像头是否开启
     AVChatManager.getInstance().toggleLocalVideo(true, null);
     avChatSurface.localVideoOn();
     isClosedCamera = false;
   }
 }
示例#6
0
 @Override
 public void toggleMute() {
   if (!isCallEstablish.get()) { // 连接未建立,在这里记录静音状态
     return;
   } else { // 连接已经建立
     if (!AVChatManager.getInstance().isMute()) { // isMute是否处于静音状态
       // 关闭音频
       AVChatManager.getInstance().setMute(true);
     } else {
       // 打开音频
       AVChatManager.getInstance().setMute(false);
     }
   }
 }
示例#7
0
 @Override
 public void closeCamera() {
   if (!isClosedCamera) {
     // 关闭摄像头
     AVChatManager.getInstance().toggleLocalVideo(false, null);
     isClosedCamera = true;
     avChatSurface.localVideoOff();
   } else {
     // 打开摄像头
     AVChatManager.getInstance().toggleLocalVideo(true, null);
     isClosedCamera = false;
     avChatSurface.localVideoOn();
   }
 }
示例#8
0
  @Override
  public void audioSwitchVideo() {
    onCallStateChange(CallStateEnum.OUTGOING_AUDIO_TO_VIDEO);
    videoParam = new VideoChatParam(avChatSurface.mCapturePreview, 0, getVideoDimens());
    /** 请求音频切换到视频 */
    AVChatManager.getInstance()
        .requestSwitchToVideo(
            videoParam,
            new AVChatCallback<Void>() {
              @Override
              public void onSuccess(Void aVoid) {
                LogUtil.d(TAG, "requestSwitchToVideo onSuccess");
              }

              @Override
              public void onFailed(int code) {
                LogUtil.d(TAG, "requestSwitchToVideo onFailed" + code);
              }

              @Override
              public void onException(Throwable exception) {
                LogUtil.d(TAG, "requestSwitchToVideo onException" + exception);
              }
            });
  }
示例#9
0
  /** 拨打音视频 */
  public void outGoingCalling(String account, AVChatType callTypeEnum) {
    DialogMaker.showProgressDialog(context, null);
    this.receiverId = account;
    VideoChatParam videoParam = null;
    if (callTypeEnum == AVChatType.AUDIO) {
      onCallStateChange(CallStateEnum.OUTGOING_AUDIO_CALLING);
    } else {
      onCallStateChange(CallStateEnum.OUTGOING_VIDEO_CALLING);
      if (videoParam == null) {
        videoParam = new VideoChatParam(avChatSurface.mCapturePreview, 0, getVideoDimens());
      }
    }

    AVChatNotifyOption notifyOption = new AVChatNotifyOption();
    notifyOption.extendMessage = "extra_data";

    /**
     * 发起通话 account 对方帐号 callTypeEnum 通话类型:语音、视频 videoParam 发起视频通话时传入,发起音频通话传null AVChatCallback
     * 回调函数,返回AVChatInfo
     */
    AVChatManager.getInstance()
        .call(
            account,
            callTypeEnum,
            videoParam,
            notifyOption,
            new AVChatCallback<AVChatData>() {
              @Override
              public void onSuccess(AVChatData data) {
                avChatData = data;
                DialogMaker.dismissProgressDialog();
              }

              @Override
              public void onFailed(int code) {
                LogUtil.d(TAG, "avChat call failed code->" + code);
                DialogMaker.dismissProgressDialog();
                if (code == ResponseCode.RES_FORBIDDEN) {
                  Toast.makeText(context, R.string.avchat_no_permission, Toast.LENGTH_SHORT).show();
                } else {
                  Toast.makeText(context, R.string.avchat_call_failed, Toast.LENGTH_SHORT).show();
                }
                closeSessions(-1);
              }

              @Override
              public void onException(Throwable exception) {
                LogUtil.d(TAG, "avChat call onException->" + exception);
                DialogMaker.dismissProgressDialog();
              }
            });
  }
示例#10
0
  /** 同意音频切换为视频 */
  private void receiveAudioToVideo() {
    AVChatManager.getInstance()
        .ackSwitchToVideo(
            true,
            videoParam,
            new AVChatCallback<Void>() {
              @Override
              public void onSuccess(Void aVoid) {
                onAudioToVideo();
                initAllSurfaceView(videoAccount);
              }

              @Override
              public void onFailed(int code) {}

              @Override
              public void onException(Throwable exception) {}
            }); // 音频切换到视频请求的回应. true为同意,false为拒绝
  }
示例#11
0
  /** 拒绝来电 */
  private void rejectInComingCall() {
    /** 接收方拒绝通话 AVChatCallback 回调函数 */
    AVChatManager.getInstance()
        .hangUp(
            new AVChatCallback<Void>() {
              @Override
              public void onSuccess(Void aVoid) {}

              @Override
              public void onFailed(int code) {
                LogUtil.d(TAG, "reject sucess->" + code);
              }

              @Override
              public void onException(Throwable exception) {
                LogUtil.d(TAG, "reject sucess");
              }
            });
    closeSessions(AVChatExitCode.REJECT);
  }
示例#12
0
  @Override
  public void videoSwitchAudio() {
    /** 请求视频切换到音频 */
    AVChatManager.getInstance()
        .requestSwitchToAudio(
            new AVChatCallback<Void>() {
              @Override
              public void onSuccess(Void aVoid) {
                // 界面布局切换。
                onCallStateChange(CallStateEnum.AUDIO);
                onVideoToAudio();
              }

              @Override
              public void onFailed(int code) {}

              @Override
              public void onException(Throwable exception) {}
            });
  }
示例#13
0
  /** 接听来电 */
  private void receiveInComingCall() {
    // 接听,告知服务器,以便通知其他端
    VideoChatParam videoParam = null;

    if (callingState == CallStateEnum.INCOMING_AUDIO_CALLING) {
      onCallStateChange(CallStateEnum.AUDIO_CONNECTING);
    } else {
      onCallStateChange(CallStateEnum.VIDEO_CONNECTING);
      videoParam = new VideoChatParam(avChatSurface.mCapturePreview, 0, getVideoDimens());
    }

    /** 接收方接听电话 videoParam 接听视频通话时传入,接听音频通话传null AVChatCallback 回调函数。成功则连接建立,不成功则关闭activity。 */
    AVChatManager.getInstance()
        .accept(
            videoParam,
            new AVChatCallback<Void>() {
              @Override
              public void onSuccess(Void v) {
                LogUtil.i(TAG, "accept success");

                isCallEstablish.set(true);
                canSwitchCamera = true;
              }

              @Override
              public void onFailed(int code) {
                if (code == -1) {
                  Toast.makeText(context, "本地音视频启动失败", Toast.LENGTH_SHORT).show();
                } else {
                  Toast.makeText(context, "建立连接失败", Toast.LENGTH_SHORT).show();
                }
                LogUtil.e(TAG, "accept onFailed->" + code);
                closeSessions(AVChatExitCode.CANCEL);
              }

              @Override
              public void onException(Throwable exception) {
                LogUtil.d(TAG, "accept exception->" + exception);
              }
            });
  }
示例#14
0
  /**
   * 挂断
   *
   * @param type 音视频类型
   */
  private void hangUp(final int type) {
    if (type == AVChatExitCode.HANGUP
        || type == AVChatExitCode.PEER_NO_RESPONSE
        || type == AVChatExitCode.CANCEL) {
      AVChatManager.getInstance()
          .hangUp(
              new AVChatCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid) {}

                @Override
                public void onFailed(int code) {
                  LogUtil.d(TAG, "hangup onFailed->" + code);
                }

                @Override
                public void onException(Throwable exception) {
                  LogUtil.d(TAG, "hangup onException->" + exception);
                }
              });
    }
    closeSessions(type);
  }
示例#15
0
 /** // 恢复视频聊天(用于视频聊天退到后台后,从后台恢复时调用) */
 public void resumeVideo() {
   AVChatManager.getInstance().resumeVideo(avChatSurface.isLocalPreviewInSmallSize());
 }
示例#16
0
 /** 拒绝音视频切换 */
 private void rejectAudioToVideo() {
   onCallStateChange(CallStateEnum.AUDIO);
   AVChatManager.getInstance()
       .ackSwitchToVideo(false, videoParam, null); // 音频切换到视频请求的回应. true为同意,false为拒绝
   updateRecordTip();
 }
示例#17
0
 @Override
 public void switchCamera() {
   AVChatManager.getInstance().toggleCamera(); // 切换摄像头(主要用于前置和后置摄像头切换)
 }
示例#18
0
 @Override
 public void toggleSpeaker() {
   AVChatManager.getInstance()
       .setSpeaker(!AVChatManager.getInstance().speakerEnabled()); // 设置扬声器是否开启
 }