|
|
|
# 关于如何接入SDK连麦功能
|
|
|
|
|
|
|
|
本文主要介绍如何接入SDK的连麦功能,为了您更好的接入连麦功能,请务必阅读本文
|
|
|
|
|
|
|
|
- [关于如何接入SDK连麦功能](#关于如何接入sdk连麦功能)
|
|
|
|
- [1.连麦核心方法介绍](#1连麦核心方法介绍)
|
|
|
|
- [1.1 主动调用方法](#11-主动调用方法)
|
|
|
|
- [1.2 回调方法](#12-回调方法)
|
|
|
|
- [2.连麦集成步骤](#2连麦集成步骤)
|
|
|
|
- [2.1 设置远端布局](#21-设置远端布局)
|
|
|
|
- [2.2 初始化画面](#22-初始化画面)
|
|
|
|
- [2.3 设置画面并设置监听](#23-设置画面并设置监听)
|
|
|
|
- [2.4 监听连麦回调](#24-监听连麦回调)
|
|
|
|
|
|
|
|
## 1.连麦核心方法介绍
|
|
|
|
|
|
|
|
### 1.1 主动调用方法
|
|
|
|
|
|
|
|
连麦核心方法都在DWLive.java类里,核心方法如下
|
|
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
|
| ------------------------------------------------------------ | ------------------ |
|
|
|
|
| setRtcClientParameters(RtcClientListener,SurfaceViewRenderer,CCRTCRender) | 设置监听和显示控件 |
|
|
|
|
| setRtcClientListener(RtcClientListener rtcClientListener) | 单独设置监听事件 |
|
|
|
|
| startRtcConnect() | 申请视频连麦 |
|
|
|
|
| startVoiceRTCConnect() | 申请音频连麦 |
|
|
|
|
| startRtcConnect(RtcClient.RtcConnectType type) | 开始连麦 |
|
|
|
|
| disConnectSpeak() | 断开连麦 |
|
|
|
|
| disConnectApplySpeak() | 断开申请连麦状态 |
|
|
|
|
| closeCamera() | 关闭摄像头并释放 |
|
|
|
|
| removeLocalRender() | 移除本地摄像头预览 |
|
|
|
|
|
|
|
|
### 1.2 回调方法
|
|
|
|
|
|
|
|
回调方法主要在类DWLiveRTCListener中,方法如下
|
|
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
|
| ------------------------------------------------------------ | ---------------------------- |
|
|
|
|
| onEnterSpeak(boolean isVideoRtc, boolean needAdjust, final String videoSize) | 主播端接通连麦,开始调用连麦 |
|
|
|
|
| onDisconnectSpeak() | 连麦断开 |
|
|
|
|
| onSpeakError(Exception e) | 连麦出现异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 2.连麦集成步骤
|
|
|
|
|
|
|
|
### 2.1 设置远端布局
|
|
|
|
|
|
|
|
首先需要设置需要显示的布局,用来显示远端画面,由于直播后台已将本地视频和远端视频合成一路流,所以只需要显示远端布局就可以
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<com.bokecc.sdk.mobile.live.rtc.CCRTCRender
|
|
|
|
android:id="@+id/svr_remote_render"
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
android:layout_height="match_parent" />
|
|
|
|
```
|
|
|
|
|
|
|
|
### 2.2 初始化画面
|
|
|
|
|
|
|
|
需要对CCRTCRender进行一系列的初始化
|
|
|
|
|
|
|
|
```java
|
|
|
|
...
|
|
|
|
CCRTCRender remoteRender;
|
|
|
|
...
|
|
|
|
EglBase rootEglBase = EglBase.create();
|
|
|
|
remoteRender.init(rootEglBase.getEglBaseContext(), null);
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
### 2.3 设置画面并设置监听
|
|
|
|
|
|
|
|
调用方法如下
|
|
|
|
|
|
|
|
```java
|
|
|
|
DWLive dwLive = DWLive.getInstance();
|
|
|
|
if (dwLive != null) {
|
|
|
|
dwLive.setRtcClientParameters(rtcClientListener, localRender, remoteRender);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 2.4 监听连麦回调
|
|
|
|
|
|
|
|
监听连麦开始事件
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
public void onEnterSpeak(final boolean isVideoRtc, final boolean needAdjust, final String videoSize) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// 关闭直播画面
|
|
|
|
// 开启连麦画面
|
|
|
|
});
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
监听连麦断开事件
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
public void onDisconnectSpeak() {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// 判断直播状态并恢复直播画面
|
|
|
|
// 释放连麦
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
监听连麦错误事件
|
|
|
|
|
|
|
|
```java
|
|
|
|
public void speakError(final Exception e) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// 弹出提示
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|