Android腾讯云直播开发,笔记:腾讯云直播SDK测试demo

本文记录了使用腾讯云直播SDK在Android平台上开发直播demo的过程,包括初始化、设置摄像头、推流参数调整、美颜滤镜等功能的实现。提供了一个简单的入门指南,适合初学者参考。
摘要由CSDN通过智能技术生成

看着腾讯直播的官方指导接入SDK,写了一个demo,有点简陋并且没全部demo应用,有空再更新吧,先做个笔记Mark先

demo地址

import android.content.DialogInterface;

import android.content.res.Configuration;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.Build;

import android.os.Bundle;

import android.os.Environment;

import android.support.v7.app.AlertDialog;

import android.support.v7.app.AppCompatActivity;

import android.util.Log;

import android.util.TypedValue;

import android.view.Surface;

import android.view.View;

import android.widget.SeekBar;

import android.widget.TextView;

import android.widget.Toast;

import com.tencent.rtmp.ITXLivePushListener;

import com.tencent.rtmp.TXLiveConstants;

import com.tencent.rtmp.TXLivePushConfig;

import com.tencent.rtmp.TXLivePusher;

import com.tencent.rtmp.ui.TXCloudVideoView;

import com.tencent.ugc.TXRecordCommon;

import static com.tencent.rtmp.TXLiveConstants.PAUSE_FLAG_PAUSE_AUDIO;

import static com.tencent.rtmp.TXLiveConstants.PAUSE_FLAG_PAUSE_VIDEO;

public class StartLiveActivity extends AppCompatActivity{

private TXLivePushConfig mLivePushConfig;

private TXCloudVideoView mCaptureView;

private TXLivePusher mLivePusher;

//设置清晰度

private boolean mAutoBitrate;//画质优先

private boolean mAutoResolution;//分辨率优先

private int mVideoQuality = TXLiveConstants.VIDEO_QUALITY_HIGH_DEFINITION;//直播视频质量

//美颜

private int mBeautyStyle;//磨皮风格: 0:光滑 1:自然 2:朦胧

private int mBeautyLevel;//磨皮等级: 取值为 0-9.取值为 0 时代表关闭美颜效果.默认值: 0,即关闭美颜效果.;

private int mWhiteningLevel;//美白等级: 取值为 0-9.取值为 0 时代表关闭美白效果.默认值: 0,即关闭美白效果.

private int mRuddyLevel;//红润等级: 取值为 0-9.取值为 0 时代表关闭美白效果.默认值: 0,即关闭美白效果.

//滤镜

private int filterIndex;//滤镜图片

private int filterDegree;//滤镜程度

private float expouseCompensation;//曝光值

//摄像头

private boolean mFlashTurnOn=true;//是否开启

private boolean mTouchFocus=false;//是否手动(true)自动对焦(false),默认手动

//设置水印

private boolean isLogo=true;//true设置,false不设置

private boolean HWVideoCode =true;//是否开启软(false,默认)硬件编码(true)

//本地录制

private TextView recordTv;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_live);

recordTv=findViewById(R.id.recordTv);

mLivePusher = new TXLivePusher(this);

mLivePushConfig = new TXLivePushConfig();

mLivePushConfig.setTouchFocus(mTouchFocus);//是否自动对焦

mLivePushConfig.setFrontCamera(true);//是否前置摄像头

initLogo();//设置水印

initHardWareCode();//软硬件编码

setPasueBackImg();//后台推流,设置主播暂停背景图

//horizontalPushCustom();//调整观众端表现

//horizontalPushLiver();//调整主播端表现

initLiveType();//开播类型

}

@Override

protected void onResume() {

super.onResume();

//10.4 切前台处理

//mCaptureView.onResume(); // mCaptureView 是摄像头的图像渲染view

//mLivePusher.resumePusher(); // 通知 SDK 重回前台推流

}

@Override

protected void onStop() {

super.onStop();

//10.3 切后台处理

//mCaptureView.onPause(); // mCaptureView 是摄像头的图像渲染view

//mLivePusher.pausePusher(); // 通知 SDK 进入“后台推流模式”了

//10.4 后台推摄像头采集数据

//如果希望主播在切后台或者跳转其他界面还能看到摄像头采集的画面, 按照以下配置即可。

//1、step 10.1 和 step 10.2 无需设置。

//2、在 step 10.3 中,注释 mLivePusher.pausePusher() 该方法。

//3、在 step 10.4 中,注释 mLivePusher.resumePusher() 该方法。

}

@Override

protected void onDestroy() {

super.onDestroy();

stopRtmpPublish();//结束推流

}

//开播类型

private void initLiveType() {

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("开始纯音频直播还是音视频直播");

builder.setIcon(R.mipmap.ic_launcher);

builder.setMessage("请选择纯音频直播或是音视频直播");

builder.setPositiveButton("音视频直播", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

initStartLive();//开始直播

}

});

builder.setNegativeButton("纯音频直播", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

initOnlyVoiceLive();

}

});

builder.show();

}

//纯音频直播

private void initOnlyVoiceLive() {

// 只有在推流启动前设置启动纯音频推流才会生效,推流过程中设置不会生效。

mLivePushConfig.enablePureAudioPush(true); // true 为启动纯音频推流,而默认值是 false;

mLivePusher.setConfig(mLivePushConfig); // 重新设置 config

String rtmpUrl = Constant.START_LIVE_URL;//开始直播的推流地址

mLivePusher.startPusher(rtmpUrl);

}

//开始直播

private void initStartLive() {

mLivePusher.setConfig(mLivePushConfig);

String rtmpUrl = Constant.START_LIVE_URL;//开始直播的推流地址

mLivePusher.startPusher(rtmpUrl);

mCaptureView = (TXCloudVideoView) findViewById(R.id.video_view);

mLivePusher.startCameraPreview(mCaptureView);

}

//纯音频直播

public void voiceLive(View view) {

Log.e("uuuuuuuu :", "纯音频直播");

initOnlyVoiceLive();

}

//设置清晰度

public void setDifinition(View view) {

Log.e("uuuuuuuu :", "设置清晰度");

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);

final String[] arrayOfString = {"秀场直播", "手游直播", "连麦(主画面)", "连麦(小画面)", "视频通话"};

localBuilder

.setTitle("设置清晰度")

.setIcon(R.mipmap.ic_launcher)

.setItems(arrayOfString, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {

switch (paramAnonymousInt) {

case 0://秀场直播

mAutoBitrate = false;

mAutoResolution = false;

//VIDEO_QUALITY_SUPER_DEFINITION

mVideoQuality = TXLiveConstants.VIDEO_QUALITY_HIGH_DEFINITION;

mLivePusher.setVideoQuality(mVideoQuality, mAutoBitrate, mAutoResolution);

break;

case 1://手游直播

mAutoBitrate = true;

mAutoResolution = true;

mVideoQuality = TXLiveConstants.VIDEO_QUALITY_SUPER_DEFINITION;

mLivePusher.setVideoQuality(mVideoQuality, mAutoBitrate, mAutoResolution);

break;

case 2://连麦(主画面)

mAutoBitrate = true;

mAutoResolution = true;

mVideoQu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值