|
|
# SDK直播核心功能集成
|
|
|
|
|
|
[TOC]
|
|
|
|
|
|
## 1. 登录
|
|
|
|
|
|
### 1.1 主动调用API
|
|
|
直播需要主动调用的方法在DWPushSession.java中(DWPushSession为单例)中,如下:
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------------------------------------- | :-------------- |
|
|
|
| getInstance() | 获取DWLogin实例 |
|
|
|
| login(String userId, String roomId, String username, String password,final OnLoginStatusListener loginStatusListener) | 登录 |
|
|
|
| release() | 释放 |
|
|
|
### 1.2 回调事件API
|
|
|
#### 1.2.1 OnLoginStatusListener
|
|
|
登录回调
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------- | :--------------- |
|
|
|
| void successed() | 登录成功后的回调 |
|
|
|
| void failed(DWPushException e) | 登录失败后回调 |
|
|
|
|
|
|
### 1.3 关键代码示例
|
|
|
登录
|
|
|
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.login(userId, roomId, username, password, onLoginStatusListener);
|
|
|
......
|
|
|
```
|
|
|
释放
|
|
|
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.release();
|
|
|
......
|
|
|
```
|
|
|
|
|
|
## 2. 推流
|
|
|
|
|
|
### 2.1 主动调用API
|
|
|
|
|
|
##### 2.1.1 推流配置构建
|
|
|
推流时的配置构建需要主动调用DWPushConfigBuilder.java(Build模式),如下:
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------------------------- | :--------------------------- |
|
|
|
| DWPushConfigBuilder() | 构建DWPushSessionBuilder实例 |
|
|
|
| cameraType(@CameraType int cameraType) | 相机类型 |
|
|
|
| orientation(@Orientation int orientation) | 推流方向 |
|
|
|
| videoResolution(@Resolution int videoResolution) | 推流分辨率 |
|
|
|
| bitrate(int bitrate) | 码率 |
|
|
|
| fps(int fps) | 帧率 |
|
|
|
| beauty(boolean isBeauty) | 是否使用美颜 |
|
|
|
| rtmpNodeIndex(int index) | 选择推送节点 |
|
|
|
| build() | 构建DWPushConfig实例 |
|
|
|
##### 2.1.2 推流操作
|
|
|
推流相关操作需要主动调用DWPushSession.java,如下:
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------------------------------------- | :-------------- |
|
|
|
| setTextureView(DWTextureView textureView) | 设置渲染层 |
|
|
|
| prepare(DWPushConfig pushConfig) | 开始预览 |
|
|
|
| start(DWPushConfig pushConfig, DWOnPushStatusListener pushStatusListener) | 开始推流 |
|
|
|
| updateVolume(int volume) | 调节音量 |
|
|
|
| updateBeautifulLevel(whiteLevel, skinLevel, pinkLevel) | 调节美颜 |
|
|
|
| closeBeauty() | 关闭美颜 |
|
|
|
| openBeauty() | 打开美颜 |
|
|
|
| updateIcon(Bitmap bitmap, Rect rect) | 调节水印 |
|
|
|
| setIcon(Bitmap bitmap, Rect rect) | 初始化水印 |
|
|
|
| setBeautifulLevel(int whiteLevel, int skinBlurLevel, int pinkLevel) | 初始化美颜级别 |
|
|
|
| setVolume(int volume) | 初始化音量 |
|
|
|
| onResume(boolean isPush) | 生命周期 |
|
|
|
| onPause() | 生命周期 |
|
|
|
| onDestory() | 生命周期 |
|
|
|
| switchCamera() | 切换摄像头 |
|
|
|
| toggleFlashlight() | 开启/关闭闪光灯 |
|
|
|
| getRoomUserCount() | 获取直播间人数 |
|
|
|
| sendChatMsgToAll(String msg) | 发送公聊信息 |
|
|
|
| sendMsgToOne(String userId, String userName, String msg) | 发送私聊信息 |
|
|
|
| stop() | 停止推流 |
|
|
|
**注意**:getRoomUserCount**该方法俩次调用时间间隔最少5S 少于5S SDK内屏蔽当前请求
|
|
|
|
|
|
### 2.2 回调事件API
|
|
|
#### 2.2.1 DWOnPushStatusListener
|
|
|
推流回调
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :------------------------------------------ | :------------------------------ |
|
|
|
| onConfigMessage(String liveId) | 配置信息liveid回调 |
|
|
|
| onSuccessed() | 连接成功回调 |
|
|
|
| onDisconnected() | 连接断开回调 |
|
|
|
| fonFailed(String message) | 连接失败回调 |
|
|
|
| onReconnect() | 重连回调 |
|
|
|
| onClosed(int action) | 连接关闭回调 |
|
|
|
| (新增)onCurrentInfo(LiveCurrentInfo info) | 回调直播中的信息LiveCurrentInfo |
|
|
|
#### 2.2.2 OnChatMsgListener
|
|
|
聊天回调
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------------------------------------- | :--------------- |
|
|
|
| onReceivedPublic(ChatUser from, ChatMsg msg, boolean isPublisher) | 接收公聊信息回调 |
|
|
|
| onReceivedPrivate(ChatUser from, ChatUser to, ChatMsg msg, boolean isPublisher) | 接收私聊信息回调 |
|
|
|
| onError(String errorMsg) | 聊天出现错误 |
|
|
|
#### 2.2.3 OnChatRoomListener
|
|
|
直播间回调
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :------------------------------- | :--------------------- |
|
|
|
| onRoomUserCountUpdate(int count) | 成功获取直播间人数回调 |
|
|
|
|
|
|
### 2.3 关键示例代码
|
|
|
#### 2.3.1 构建DWPushConfig实例
|
|
|
```java
|
|
|
......
|
|
|
DWPushConfig pushConfig = new DWPushConfig.DWPushConfigBuilder().
|
|
|
fps(mFpsCurrentValue).
|
|
|
bitrate(mBitrateCurrentValue).
|
|
|
orientation(mOrientationIndex).
|
|
|
cameraType(mCameraTypeIndex).
|
|
|
beauty(mUseBeauty).
|
|
|
rtmpNodeIndex(mRecommendIndex).
|
|
|
build();
|
|
|
......
|
|
|
```
|
|
|
|
|
|
#### 2.3.2 开始推流
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.start(pushConfig, dwOnPushStatusListener):
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.3 停止推流
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.stop():
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.4 切换摄像头
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.switchCamera():
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.5 开启/关闭闪光灯
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.toggleFlashlight():
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.6 初始化音量
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.setVolume(volume):
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.7 初始化美颜级别
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.setBeautifulLevel(whiteLevel, skinLevel, pinkLevel):
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.8 初始化水印
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.setIcon(bitmap, rect):
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.9 推流过程中调节音量
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.updateVolume(value):
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.10 推流过程中调节美颜级别
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.updateBeautifulLevel(whiteLevel, skinLevel, pinkLevel);
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.11 推流过程中更新水印
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.updateIcon(bitmap, rect);
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.12 发送公聊
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.sendChatMsgToAll(msg);
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.13 发送私聊
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.sendMsgToOne(userId, userName, msg);
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.14 获取直播间人数
|
|
|
```java
|
|
|
......
|
|
|
DWPushSession pushSession = DWPushSession.getInstance();
|
|
|
pushSession.getRoomUserCount()
|
|
|
......
|
|
|
```
|
|
|
#### 2.3.15 布局文件设置DWTextureView(DWTextureView继承自TextureView):
|
|
|
|
|
|
```xml
|
|
|
......
|
|
|
<com.bokecc.sdk.mobile.push.view.DWTextureView
|
|
|
android:id="@+id/id_push_gl_surface"
|
|
|
android:layout_width="match_parent"
|
|
|
android:layout_height="match_parent"/>
|
|
|
......
|
|
|
```
|
|
|
|
|
|
**注意**<br/>
|
|
|
**DWTextureView**初始化,具体参考demo
|
|
|
|
|
|
### 2.4 备注
|
|
|
必须把DWPushSession与Activity的生命周期进行统一管理,如下
|
|
|
|
|
|
```java
|
|
|
......
|
|
|
// 这里需要注意生命周期的使用
|
|
|
@Override
|
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
|
session.onResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
|
session.onPause();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
session.onDestory();
|
|
|
}
|
|
|
......
|
|
|
```
|
|
|
|
|
|
|
|
|
## 3. 测速
|
|
|
### 3.1 主动调用API
|
|
|
测速需要主动调用API在DWRtmpNodeTool.java(工具类,不可实例化)中,如下:
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :----------------------------------------------------------- | :------- |
|
|
|
| testSpeedForRtmpNodes(final OnTestSpeedFinishListener listener) | 节点测速 |
|
|
|
### 3.2 回调事件API
|
|
|
#### 3.2.1 OnTestSpeedFinishListener
|
|
|
测速回调
|
|
|
|
|
|
| 方法 | 说明 |
|
|
|
| :------------------------------------------- | :----------- |
|
|
|
| onFinish(ArrayList<SpeedRtmpNode> rtmpNodes) | 测速完成回调 |
|
|
|
| void onError(String message) | 测速出错回调 |
|
|
|
|
|
|
### 3.3 关键示例代码
|
|
|
```java
|
|
|
......
|
|
|
DWRtmpNodeTool.testSpeedForRtmpNodes(onTestSpeedFinishListener);
|
|
|
......
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 4. demo使用
|
|
|
|
|
|
1. 在res/values/strings.xml里面进行测试账号配置
|
|
|
</br>
|
|
|
2. 通过扫描二维码或者手动输入账号信息
|
|
|
|
|
|
注:目前demo是Android Studio版本。
|
|
|
|
|
|
|
|
|
|
|
|
</br></br></br></br></br>
|
|
|
*(已经到底部)* |
|
|
\ No newline at end of file |