|
|
## 多人连麦接入文档
|
|
|
|
|
|
[TOC]
|
|
|
|
|
|
### 接入基本信息
|
|
|
|
|
|
| 基本信息 | 说明 |
|
|
|
| ----------------------- | ------------------- |
|
|
|
| 支持版本 | 3.18.0及后续版本 |
|
|
|
| 接入方式 | 本地、maven远程依赖 |
|
|
|
| 支持Android API最低版本 | 18 |
|
|
|
|
|
|
|
|
|
|
|
|
### 主动调用
|
|
|
|
|
|
|
|
|
|
|
|
#### 是否是多人连麦
|
|
|
|
|
|
| 方法 | 注视 |
|
|
|
| -------------------- | -------------- |
|
|
|
| `isMultiMediaCall()` | 是否是多人连麦 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().isMultiMediaCall()
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 主动申请上麦
|
|
|
|
|
|
| 方法 | 注视 |
|
|
|
| ------------------------------------------------------------ | ------------ |
|
|
|
| `public void callInPreviewWithType(RtcCallBack rtcCallBack, BaseRtcClient.RtcConnectType type)` | 主动申请上麦 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
|
|
|
DWLive.getInstance().callInPreviewWithType(new RtcCallBack() {
|
|
|
@Override
|
|
|
public void onFail(int code) {
|
|
|
//code (StreamErrorCode)-1:rtc连接超时;-2:初始化失败;-3:远端流失败;-4:rtc连接断开;-5:主动发起60s未收到老师同意;-8:连麦人数超限制
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(HDMediaView hdMediaView) {
|
|
|
//hdMediaView 本地摄像头预览view,可能为null,单人连麦为null,音频连麦为null
|
|
|
}
|
|
|
},videoRtc?BaseRtcClient.RtcConnectType.AUDIOVIDEO:BaseRtcClient.RtcConnectType.AUDIO);
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 同意上麦(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | -------- |
|
|
|
| `public void agreeCallInPreview(RtcCallBack rtcCallBack, BaseRtcClient.RtcConnectType type)` | 同意上麦 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
|
|
|
DWLive.getInstance().agreeCallInPreview(new RtcCallBack() {
|
|
|
@Override
|
|
|
public void onFail(int code) {
|
|
|
//code (StreamErrorCode)-1:rtc连接超时;-2:初始化失败;-3:远端流失败;-4:rtc连接断开;-5:主动发起60s未收到老师同意;-8:连麦人数超限制
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(HDMediaView hdMediaView) {
|
|
|
//hdMediaView 本地摄像头预览view,可能为null,单人连麦为null,音频连麦为null
|
|
|
}
|
|
|
},isVideoRtc()?BaseRtcClient.RtcConnectType.AUDIOVIDEO:BaseRtcClient.RtcConnectType.AUDIO);
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 拒绝上麦(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| -------------------------- | -------- |
|
|
|
| `public void rejectCall()` | 拒绝上麦 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().rejectCall();
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 挂断(下课也需要调用)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ----------------------------------------------- | ---- |
|
|
|
| `public void hangup(BaseCallback baseCallback)` | 挂断 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
/**
|
|
|
* 学员主动挂断
|
|
|
* 主动挂断连麦,用户主动点击下麦按钮时需要在onSuccess中处理下游逻辑,退出直播间、下课等调用 hangup时不需要关心callback
|
|
|
*/
|
|
|
DWLive.getInstance().hangup(new BaseCallback() {
|
|
|
@Override
|
|
|
public void onError(String error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(Object msg) {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 设置本地视频开启(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------- | ---------------------------------- |
|
|
|
| `public void setLocalVideoEnable(boolean enable)` | 设置本地视频开启(开始直播之后生效) |
|
|
|
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().setLocalVideoEnable(on);
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 设置本地音频开启(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------- | ---------------------------------- |
|
|
|
| `public void setLocalAudioEnable(boolean enable)` | 设置本地音频开启(开始直播之后生效) |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().setLocalAudioEnable(on);
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 切换本地摄像头(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| --------------------------------- | ------------------------ |
|
|
|
| `public void switchLocalCamera()` | 切换本地摄像头,默认前置 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().switchLocalCamera();
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 拉取远端流
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ---------- |
|
|
|
| `public void pullRemoteStream(String userId, PullRemoteStreamCallBack baseCallback) ` | 拉取远端流 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().pullRemoteStream(userId, new PullRemoteStreamCallBack() {
|
|
|
@Override
|
|
|
public void onError(String error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(HDMediaView view, RemoteStreamInfo info) {
|
|
|
//view surface渲染视图 info:userId、userName、isAllowAudio、isAllowVideo
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 移除远端流(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ---------- |
|
|
|
| `public void removeRemoteStream(String userId, BaseCallback baseCallback)` | 移除远端流 |
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
DWLive.getInstance().removeRemoteStream(userId,null);
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 接口
|
|
|
|
|
|
#### 连麦相关接口 RTCConnectListener
|
|
|
|
|
|
##### 房间是否允许连麦
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ---------------- |
|
|
|
| `void onMediaCallStatusDidChange(boolean isAllowSpeak, BaseRtcClient.RtcConnectType type)` | 房间是否允许连麦 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 远端流可用
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ---------- |
|
|
|
| `void onRemoteStreamEnable(String userId, String hdLiveMediaCallRole)` | 远端流可用 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 远端流不可用(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------- | ------------ |
|
|
|
| `void onRemoteStreamDisable(String userId)` | 远端流不可用 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 邀请上麦(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| --------------------- | -------- |
|
|
|
| `void onInviteCall()` | 邀请上麦 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 取消邀请(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------- | -------- |
|
|
|
| `void onInviteCanceled()` | 取消邀请 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 音频状态改变(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ------------ |
|
|
|
| `void onAudioStatusDidChange(String userId, boolean isAllowAudio, boolean isSelf)` | 音频状态改变 |
|
|
|
|
|
|
备注:主动更改音频状态,不会回调此方法
|
|
|
|
|
|
|
|
|
|
|
|
##### 视频状态改变(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ------------ |
|
|
|
| `void onVideoStatusDidChange(String userId, boolean isAllowVideo, boolean isSelf)` | 视频状态改变 |
|
|
|
|
|
|
备注:主动更改视频状态,不会回调此方法
|
|
|
|
|
|
|
|
|
|
|
|
##### 被挂断(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------ | ------ |
|
|
|
| `void onCallWasHangup()` | 被挂断 |
|
|
|
|
|
|
|
|
|
|
|
|
##### 连麦异常
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| -------------------------------------- | -------- |
|
|
|
| `void onConnectionException(int code)` | 连麦异常 |
|
|
|
|
|
|
|
|
|
|
|
|
示例代码
|
|
|
|
|
|
```java
|
|
|
RTCConnectListener rtcConnectOutListener = new RTCConnectListener() {
|
|
|
|
|
|
@Override
|
|
|
public void onInviteCall() {
|
|
|
//收到邀请
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onInviteCanceled() {
|
|
|
//收到取消邀请
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCallWasHangup() {
|
|
|
//连麦被挂断
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onConnectionException(int code) {
|
|
|
//code(StreamErrorCode) -3:远端流失败;-4:rtc连接断开
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onRemoteStreamEnable(String userId, String role) {
|
|
|
//远端流可用
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onRemoteStreamDisable(String userId) {
|
|
|
//远端流不可用
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onMediaCallStatusDidChange(boolean isAllowSpeak, BaseRtcClient.RtcConnectType type) {
|
|
|
//连麦服务变更 isAllowSpeak:是否允许连麦;type:连麦类型(AUDIO、AUDIOVIDEO)
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onAudioStatusDidChange(String userid, boolean isAllowAudio, boolean isSelf) {
|
|
|
//音频状态改变
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onVideoStatusDidChange(String userid, boolean isAllowVideo, boolean isSelf) {
|
|
|
//视频状态改变
|
|
|
}
|
|
|
};
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 直播间连麦相关接口 DWLiveListener
|
|
|
|
|
|
##### 连麦模式切换(多人连麦)
|
|
|
|
|
|
| 方法 | 注释 |
|
|
|
| ------------------------------------------------------------ | ------------ |
|
|
|
| `public void onMediaCallModeDidChange(LiveStreamPlayMode.MODE mode)` | 连麦模式切换 |
|
|
|
|
|
|
##### 异常onException
|
|
|
|
|
|
| ErrorCode | 注释 |
|
|
|
| ------------------------------- | ------------------------ |
|
|
|
| `ErrorCode.ROOM_SETTING_CHANGE` | 单人连麦切换多人连麦抛错 |
|
|
|
| `ErrorCode.STREAM_ERROR` | 连麦视频流错误 |
|
|
|
|
|
|
|
|
|
|
|
|
#### 特别注意多人连麦在下述情况下需要退出房间重新登录
|
|
|
|
|
|
1. DWLiveListener回调onException时,errorCode是`ErrorCode.ROOM_SETTING_CHANGE`必须重新登录,是`ErrorCode.STREAM_ERROR`时如果需要重新发起连麦,必须要重新登录。
|
|
|
|