# LiveTest
**Repository Path**: jackning_admin/LiveTest
## Basic Information
- **Project Name**: LiveTest
- **Description**: 腾讯云直播sdkDmoe简单接入,实现了发起直播、加入直播间、推流、拉流、短视频等功能
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2018-10-08
- **Last Updated**: 2022-05-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# LiveTest
#### 项目介绍
腾讯云直播sdkDemo简单接入,实现了发起直播、加入直播间、连麦、主播pk、聊天、推流、拉流、特效等功能
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. 项目地址: https://gitee.com/jackning_admin/LiveTest
2. 集成步骤:这里我只集成了直播,大家可以去官网集成全功能专业版(包含短视频和直播)
a.导入直播aar和腾讯IMaar,第三方包
//腾讯云直播精简版SDK,
implementation(name: 'LiteAVSDK_Smart_5.1.5293', ext: 'aar')
//腾讯IM
implementation(name: 'liteimsdk-release', ext: 'aar')
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
implementation 'com.google.code.gson:gson:2.8.4'
3. 所需权限:
4.初始化:在Application中初始化直播ID
/**
* 作者: njb
* 时间: 2018/8/29 0029-上午 11:51
* 描述: 初始化
* 来源:
*/
public class App extends MultiDexApplication {
private static App instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
//知识化直播
initLive();
}
/**
* 初始化直播信息
*/
private void initLive() {
TXLiveBase.setConsoleEnabled(true);
TXLiveBase.setAppID("1252463788");
}
public static App getApplication() {
return instance;
}
}
5.实际项目中要注意推流和拉流地址,刚开始由于不熟悉,弄反了,锁屏或者进行其他操作就一直黑屏
//推流地址格式:rtmp://8888.livepush.myqcloud.com/path/8888_test_12345_test?txSecret=aaaa&txTime=bbbb
//拉流地址格式:rtmp://8888.liveplay.myqcloud.com/path/8888_test_12345_test
// http://8888.liveplay.myqcloud.com/path/8888_test_12345_test.flv
// http://8888.liveplay.myqcloud.com/path/8888_test_12345_test.m3u8
项目中代码直播部分示例
/**
* 初始化推流
*/
private void initPushView() {
//创建推流对象
mLivePusher = new TXLivePusher(this);
//配置推流
mLivePushConfig = new TXLivePushConfig();
mLivePushConfig.setVideoEncodeGop(5);
mLivePusher.setConfig(mLivePushConfig);
if (mLivePusher.isPushing()) {
if (VIDEO_SRC_CAMERA == mVideoSrc) {
mLivePusher.setConfig(mLivePushConfig);
} else if (VIDEO_SRC_SCREEN == mVideoSrc) {
mLivePusher.setConfig(mLivePushConfig);
mLivePusher.stopScreenCapture();
mLivePusher.startScreenCapture();
}
} else mLivePusher.setConfig(mLivePushConfig);
mLivePusher.setRenderRotation(renderRotation);
mVideoPublish = true;
}
/**
* 初始化拉流
*/
private void initPlayView() {
if(mLivePlayer == null) {
//创建 player 对象
mLivePlayer = new TXLivePlayer(this);
}
}
@SuppressLint("DefaultLocale")
@Override
public void onLoadLiveRoomInfo(LiveRoomInfoModel o) {
video_url = o.getPlay_url();
pushUrl = o.getPush_rtmp();//推流地址
playUrl = o.getPlay_rtmp();//拉流地址
onlineNumberTv.setText(String.format("%d人", o.getViewer_num()));
//设置直播用户信息
setUserInfo(o.getPodcast().getUser());
//启动推流
startLivePush(pushUrl);
//启动拉流
startLivePlayer(playUrl);
}
6.在Activity暂停、结束、或者锁屏进行其他时记得进行相应处理,关闭直播,释放资源
@Override
protected void onResume() {
super.onResume();
if (videoViewFullScreen != null) {
videoViewFullScreen.onResume();
}
if (mVideoPublish && mLivePusher != null && mVideoSrc == VIDEO_SRC_CAMERA) {
mLivePusher.resumePusher();//继续推流
mLivePusher.resumeBGM();//
}
mLivePlayer.resume(); //继续播放
}
@Override
public void onStop() {
super.onStop();
if (videoViewFullScreen != null) {
videoViewFullScreen.onPause();
}
if (mVideoPublish && mLivePusher != null && mVideoSrc == VIDEO_SRC_CAMERA) {
mLivePusher.pausePusher();//推流暂停
mLivePusher.pauseBGM();
}
mLivePlayer.pause();//拉流暂停
}
@Override
protected void onDestroy() {
super.onDestroy();
if (videoViewFullScreen != null) {
videoViewFullScreen.onDestroy();
}
//停止推流
stopPublishRtmp();
//停止拉流
stopPlay();
}
#### 参与贡献
#### 码云特技