[Audio and Video] Android CallLib Development Guide

Italiano

To activate audio and video services, please refer to the description of how to activate audio and video services.

Instructions for use

Due to different underlying engine technologies, the audio and video SDK after 2.6.0 and the real-time audio and video in the SDK before 2.6.0 cannot communicate with each other.

The audio and video SDK is a commercial charging function. The real-time audio and video in the previous SDK is a free test function. If you still want to use the previous real-time audio and video, you can use version 2.5.2. The instructions for using audio and video services after 2.6.0 are as follows :

Integration Instructions

1. First, please refer to the official website documentation to integrate the CallLib SDK.

2. Before using Rongyun call, you must initialize the SDK and connect to the server. For details, please refer to  the IMLib quick integration document .

Quick integration

initiate a call

You can call  RongCallClient the following interface to initiate a call.

/**
 * initiate a call
 * @param conversationType conversation type
 * @param targetId target session id
 * @param userIds List of user IDs invited to participate in the call
 * @param mediaType The media type of the call initiated
 * @param extra additional information
 * @return call id
 */
 public String startCall(Conversation.ConversationType conversationType, String targetId, List<String> userIds, RongCallCommon.CallMediaType mediaType, String extra);

Set up call monitoring

RongCallClient.setReceivedCallListener(new IRongReceivedCallListener() {    
    /**
     * 来电回调
     * @param callSession 通话实体
     */
    @Override
    public void onReceivedCall(RongCallSession callSession) {        
    //accept or hangup the call
    }    
    
    /**
     * targetSDKVersion>=23时检查权限的回调。当targetSDKVersion<23的时候不需要实现。
     * 在这个回调里用户需要使用Android6.0新增的动态权限分配接口requestCallPermissions通知用户授权,
     * 然后在onRequestPermissionResult回调里根据用户授权或者不授权分别回调
     * RongCallClient.getInstance().onPermissionGranted()和
     * RongCallClient.getInstance().onPermissionDenied()来通知CallLib。
     * 其中audio call需要获取Manifest.permission.RECORD_AUDIO权限;
     * video call需要获取Manifest.permission.RECORD_AUDIO和Manifest.permission.CAMERA两项权限。
     * @param callSession 通话实体
     */
    @Override
    public void onCheckPermission(RongCallSession callSession) {

    }
});

接听和挂断通话

您可以调用 RongCallClient 下面接口接听和挂断通话。

/**
 * 接听通话
 * @param callId 呼叫id,可以从来电监听的callSession中获取
 */public void acceptCall(String callId);
/**
 * 挂断通话
 * @param callId 呼叫id,可以从来电监听的callSession中获取
 */public void hangUpCall(String callId);

会话是否支持发起通话--call_conversation--

目前,SDK 支持在单聊中发起单人通话,在讨论组中发起多人通话。

您可以通过 RongCallClient 的下面接口查询当前会话类型的通话能力。

/**
 * 当前会话类型是否支持音频通话。
 * @param type  会话类型
 * @return      true:支持; false:不支持
 */
 public boolean isAudioCallEnabled(Conversation.ConversationType type);
 
/**
 * 当前会话类型是否支持视频通话。
 * @param type  会话类型
 * @return      true:支持; false:不支持
 */
 public boolean isVideoCallEnabled(Conversation.ConversationType type);

获取当前的通话实体

您可以通过RongCallClient的下面接口获取当前的通话实体,通话实体中维护着当前通话的所有信息。

/**
 * 获取当前通话实体,通话实体中维护着当前通话的所有信息。
 * @return 当前通话实体
 */
 public RongCallSession getCallSession();

邀请用户加入当前通话

您可以通过 RongCallClient 的下面接口邀请用户加入当前通话(仅限讨论组和群组)。

/**
 * 邀请用户加入当前通话(仅限讨论组和群组)
 * @param callId    通话id
 * @param userIds   邀请的用户id列表
 */
 public void addParticipants(String callId, List<String> userIds);

通话过程中的媒体接口

您可以通过 RongCallClient 的下面接口进行媒体类的操作。

/**
 * 切换 audio,video 通话
 * @param mediaType 要切换的媒体类型:audio、video
 */
 public void changeCallMediaType(RongCallCommon.CallMediaType mediaType);
 
/**
 * 前后摄像头切换
 */
 public void switchCamera();
 
/**
 * 设置是否打开本地摄像头
 * @param enabled true:打开摄像头;false:关闭摄像头。
 */
 public void setEnableLocalVideo(boolean enabled);
 
/**
 * 设置是否打开本地音频
 * @param enabled true:打开本地音频 false:关闭本地音频
 */
 public void setEnableLocalAudio(boolean enabled);
 
/**
 * 设置是否打开免提
 * @param enabled true:打开免提 false:关闭免提
 */
 public void setEnableSpeakerphone(boolean enabled);

设置通话状态的回调

您需要设置通话状态的回调,来监听通话状态的变化。

RongCallClient.getInstance().setVoIPCallListener(new IRongCallListener() {    
    /**
     * 电话已拨出。
     * 主叫端拨出电话后,通过回调 onCallOutgoing 通知当前 call 的详细信息。
     *
     * @param callSession 通话实体。
     * @param localVideo  本地 camera 信息。
     */
    @Override
    public void onCallOutgoing(RongCallSession callSession, SurfaceView localVideo) {

    }    
    
    /**
     * 已建立通话。
     * 通话接通时,通过回调 onCallConnected 通知当前 call 的详细信息。
     *
     * @param callSession 通话实体。
     * @param localVideo  本地 camera 信息。
     */
    @Override
    public void onCallConnected(RongCallSession callSession, SurfaceView localVideo) {

    }    
    
    /**
     * 通话结束。
     * 通话中,对方挂断,己方挂断,或者通话过程网络异常造成的通话中断,都会回调 onCallDisconnected。
     *
     * @param callSession 通话实体。
     * @param reason      通话中断原因。
     */
    @Override
    public void onCallDisconnected(RongCallSession callSession, RongCallCommon.CallDisconnectedReason reason) {

    }    
    
    /**
     * 被叫端正在振铃。
     * 主叫端拨出电话,被叫端收到请求,发出振铃响应时,回调 onRemoteUserRinging。
     *
     * @param userId 振铃端用户 id。
     */
    @Override
    public void onRemoteUserRinging(String userId) {

    }    
    
    /**
     * 被叫端加入通话。
     * 主叫端拨出电话,被叫端收到请求后,加入通话,回调 onRemoteUserJoined。
     *
     * @param userId      加入用户的 id。
     * @param mediaType   加入用户的媒体类型,audio or video。
     * @param remoteVideo 加入用户者的 camera 信息。
     */
    @Override
    public void onRemoteUserJoined(String userId, RongCallCommon.CallMediaType mediaType, SurfaceView remoteVideo) {

    }    
    
    /**
     * 通话中的某一个参与者,邀请好友加入通话,发出邀请请求后,回调 onRemoteUserInvited。
     *
     * @param userId    被邀请者的 id。
     * @param mediaType 被邀请者的 id。
     */
    @Override
    public void onRemoteUserInvited(String userId, RongCallCommon.CallMediaType mediaType) {

    }    
    
    /**
     * 通话中的远端参与者离开。
     * 回调 onRemoteUserLeft 通知状态更新。
     *
     * @param userId 远端参与者的 id。
     * @param reason 远端参与者离开原因。
     */
    @Override
    public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {

    }    
    
    /**
     * 当通话中的某一个参与者切换通话类型,例如由 audio 切换至 video,回调 onMediaTypeChanged。
     *
     * @param userId    切换者的 userId。
     * @param mediaType 切换者,切换后的媒体类型。
     * @param video     切换着,切换后的 camera 信息,如果由 video 切换至 audio,则为 null。
     */
    @Override
    public void onMediaTypeChanged(String userId, RongCallCommon.CallMediaType mediaType, SurfaceView video) {

    }    
    
    /**
     * 通话过程中,发生异常。
     *
     * @param errorCode 异常原因。
     */
    @Override
    public void onError(RongCallCommon.CallErrorCode errorCode) {

    }    
    
    /**
     * 远端参与者 camera 状态发生变化时,回调 onRemoteCameraDisabled 通知状态变化。
     *
     * @param userId   远端参与者 id。
     * @param disabled 远端参与者 camera 是否可用。
     */
    @Override
    public void onRemoteCameraDisabled(String userId, boolean disabled) {

    }
});


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324913728&siteId=291194637