如何快速搭建小直播,请参考文档:https://cloud.tencent.com/document/product/454/7999
小直播用到的各项云服务一览:
2.2 云服务开通
请参见 如何开通各项云服务?
链接地址1:https://cloud.tencent.com/document/product/454/7953
链接地址2:https://cloud.tencent.com/document/product/454/15187
特别说明:
腾讯云回调业务服务器是通过 业务服务器上的Live_callback.php 接口来实现回调处理逻辑。
直播控制台 回调URL需要配置为:`http://业务服务器IP或域名/callback/Live_callback.php`
注意:腾讯云回调此接口 http://业务服务器IP或域名/callback/Live_callback.php
3.1. 后台部署主要步骤和方式(自有服务器部署和腾讯云主机CVM部署)
请参考地址:https://cloud.tencent.com/document/product/454/7999
3.2.部署完成验证
在浏览器输入 http://您的服务器ip/interface.php
, 如果返回如下结果“{"returnValue":4001,"returnMsg":"json format error","returnData":[]}” ,说明PHP处于运行状态,并且接口可以被外部访问。说明业务后台部署完成。
这里提示“json format error”是因为请求没有带参数,小直播终端源码对接口请求做了封装,对接终端源码后请求就是正常的。详细的接口使用可以参考 小直播前后台协议解析。
注意:业务后台在此处需要提供两个URL。其中,http://业务服务器IP或域名/callback/Live_callback.php供腾讯云调用;http://您的服务器ip/interface.php供Android终端调用。
终端集成主要是小直播源码集成,主要是以下简单几步:
4.1. 小直播源码源码下载
小直播源码下载,点击后如图,下载小直播IOS和小直播Android
4.2. 终端参数一览
各个参数及其意义
参数名称 | Android变量名 | IOS变量名 | 含义 |
---|---|---|---|
SdkAppId | IMSDK_APPID | kTCIMSDKAppId | IM相关 标识一个IM应用 |
AccountType | IMSDK_ACCOUNT_TYPE | kTCIMSDKAccountType | IM相关 账号类型,小直播采用的是托管模式,创建IM应用的时候务必选择托管模式;另一种是独立模式 主要用在需要和自己已有的账号体系进行集成。 |
APPID | COS_APPID | kTCCOSAppId | 区分对象存储应用 |
Bucket名称 | COS_BUCKET | kTCCOSBucket | 指定对象存储,文件要存放的位置 |
区域代码 | COS_REGION | kTCCOSRegion | COS相关 指定Bucket所在区域,COS实际所在机房,目前有华东(sh),华北(tj),华南(gz)三个区域。 |
ServerAddr | SVR_POST_URL | kHttpServerAddr | 业务服务器后台请求地址: http://您的服务器地址或域名/interface.php |
4.3. 终端参数替换
Android 源码包解压后在app/src/main/java/com/tencent/qcloud/xiaozhibo/base目录下有一个TCConstants.java文件;同样在在IOS源码包解压后在TCLVBIMDemo/Classes/LVB/Base 目录下有一个TCConstants.h文件。并替换对应的字段值,源码中默认是空值或0。
参数获取:
SdkAppId获取,AccountType获取,COS Region 获取。
案例:
TCConstants.java文件配置如下:
package com.tencent.qcloud.xiaozhibo.common.utils;
import com.tencent.cos.common.COSEndPoint;
/**
* 静态函数
*/
public class TCConstants {
//小直播相关配置请参考:https://www.qcloud.com/document/product/454/7999
//************在腾讯云开通各项服务后,将您的配置替换到如下的几个定义中************
//云通信服务相关配置
public static final int IMSDK_ACCOUNT_TYPE = 39369;
public static final int IMSDK_APPID = 1400143781;
//COS存储服务相关配置
public static final String COS_BUCKET = "techsupport-1257281398";
public static final String COS_APPID = "1257281498";
//COS服务配置的机房区域,从COS的管理控制台https://console.qcloud.com/cos4/bucket进入Bucket列表后,选择您所创建的Bucket->基础配置->所属地区,查到所属地区后,根据如下
//对应关系填入,如是“华南”请填写COSEndPoint.COS_GZ,“华北”请填写COSEndPoint.COS_TJ,“华东”请填写COSEndPoint.COS_SH
public static final COSEndPoint COS_REGION = COSEndPoint.COS_GZ;
//云API服务密钥,在https://console.qcloud.com/capi查看,用于UGC短视频上传并落地到点播系统。已经废弃,客户端不用填写。
public static final String CLOUD_API_SECRETID = "";
//业务Server的Http配置
public static final String SVR_POST_URL = "http://14.25.136.186/interface.php";
//直播分享页面的跳转地址,分享到微信、手Q后点击观看将会跳转到这个地址,请参考https://www.qcloud.com/document/product/454/8046 文档部署html5的代码后,替换成相应的页面地址
public static final String SVR_LivePlayShare_URL = "";
//设置第三方平台的appid和appsecrect,大部分平台进行分享操作需要在第三方平台创建应用并提交审核,通过后拿到appid和appsecrect并填入这里,具体申请方式请参考http://dev.umeng.com/social/android/operation
//有关友盟组件更多资料请参考这里:http://dev.umeng.com/social/android/quick-integration
public static final String WEIXIN_SHARE_ID = "";
public static final String WEIXIN_SHARE_SECRECT = "";
public static final String SINA_WEIBO_SHARE_ID = "";
public static final String SINA_WEIBO_SHARE_SECRECT = "";
public static final String SINA_WEIBO_SHARE_REDIRECT_URL = "http://sns.whalecloud.com/sina2/callback";
public static final String QQZONE_SHARE_ID = "";
public static final String QQZONE_SHARE_SECRECT = "";
//小直播appid
public static final int XIAOZHIBO_APPID = 1257281498;
//bugly组件Appid,bugly为腾讯提供的用于App Crash收集和分析的组件
public static final String BUGLY_APPID = "";
//**********************************************************************
/**
* 常量字符串
*/
public static final String USER_INFO = "user_info";
public static final String USER_ID = "user_id";
public static final String USER_SIG = "user_sig";
public static final String USER_NICK = "user_nick";
public static final String USER_SIGN = "user_sign";
public static final String USER_HEADPIC = "user_headpic";
public static final String USER_COVER = "user_cover";
public static final String USER_LOC = "user_location";
public static final String SVR_RETURN_CODE = "returnValue";
public static final String SVR_RETURN_MSG = "returnMsg";
public static final String SVR_RETURN_DATA = "returnData";
//主播退出广播字段
public static final String EXIT_APP = "EXIT_APP";
public static final int USER_INFO_MAXLEN = 20;
public static final int TV_TITLE_MAX_LEN = 30;
public static final int NICKNAME_MAX_LEN = 20;
//直播类型
public static final int RECORD_TYPE_CAMERA = 991;
public static final int RECORD_TYPE_SCREEN = 992;
//码率
public static final int BITRATE_SLOW = 900;
public static final int BITRATE_NORMAL = 1200;
public static final int BITRATE_FAST = 1600;
//直播端右下角listview显示type
public static final int TEXT_TYPE = 0;
public static final int MEMBER_ENTER = 1;
public static final int MEMBER_EXIT = 2;
public static final int PRAISE = 3;
public static final int LOCATION_PERMISSION_REQ_CODE = 1;
public static final int WRITE_PERMISSION_REQ_CODE = 2;
public static final String PUBLISH_URL = "publish_url";
public static final String ROOM_ID = "room_id";
public static final String ROOM_TITLE = "room_title";
public static final String COVER_PIC = "cover_pic";
public static final String BITRATE = "bitrate";
public static final String GROUP_ID = "group_id";
public static final String PLAY_URL = "play_url";
public static final String PLAY_TYPE = "play_type";
public static final String PUSHER_AVATAR = "pusher_avatar";
public static final String PUSHER_ID = "pusher_id";
public static final String PUSHER_NAME = "pusher_name";
public static final String MEMBER_COUNT = "member_count";
public static final String HEART_COUNT = "heart_count";
public static final String FILE_ID = "file_id";
public static final String TIMESTAMP = "timestamp";
public static final String ACTIVITY_RESULT = "activity_result";
public static final String SHARE_PLATFORM = "share_platform";
public static final String CMD_KEY = "userAction";
public static final String DANMU_TEXT = "actionParam";
public static final String NOTIFY_QUERY_USERINFO_RESULT = "notify_query_userinfo_result";
/**
* UGC小视频录制信息
*/
public static final String VIDEO_RECORD_TYPE = "type";
public static final String VIDEO_RECORD_RESULT = "result";
public static final String VIDEO_RECORD_DESCMSG = "descmsg";
public static final String VIDEO_RECORD_VIDEPATH = "path";
public static final String VIDEO_RECORD_COVERPATH = "coverpath";
public static final String VIDEO_RECORD_ROTATION = "rotation";
public static final String VIDEO_RECORD_NO_CACHE = "nocache";
public static final String VIDEO_RECORD_DURATION = "duration";
public static final String VIDEO_RECORD_RESOLUTION = "resolution";
public static final int VIDEO_RECORD_TYPE_PUBLISH = 1; // 推流端录制
public static final int VIDEO_RECORD_TYPE_PLAY = 2; // 播放端录制
public static final int VIDEO_RECORD_TYPE_UGC_RECORD = 3; // 短视频录制
public static final int VIDEO_RECORD_TYPE_EDIT = 4; // 短视频编辑
/**
* IM 互动消息类型
*/
public static final int IMCMD_PAILN_TEXT = 1; // 文本消息
public static final int IMCMD_ENTER_LIVE = 2; // 用户加入直播
public static final int IMCMD_EXIT_LIVE = 3; // 用户退出直播
public static final int IMCMD_PRAISE = 4; // 点赞消息
public static final int IMCMD_DANMU = 5; // 弹幕消息
//ERROR CODE TYPE
public static final int ERROR_GROUP_NOT_EXIT = 10010;
public static final int ERROR_QALSDK_NOT_INIT = 6013;
public static final int ERROR_JOIN_GROUP_ERROR = 10015;
public static final int SERVER_NOT_RESPONSE_CREATE_ROOM = 1002;
public static final int NO_LOGIN_CACHE = 1265;
/**
* 用户可见的错误提示语
*/
public static final String ERROR_MSG_NET_DISCONNECTED = "网络异常,请检查网络";
//直播端错误信息
public static final String ERROR_MSG_CREATE_GROUP_FAILED = "创建直播房间失败,Error:";
public static final String ERROR_MSG_GET_PUSH_URL_FAILED = "拉取直播推流地址失败,Error:";
public static final String ERROR_MSG_OPEN_CAMERA_FAIL = "无法打开摄像头,需要摄像头权限";
public static final String ERROR_MSG_OPEN_MIC_FAIL = "无法打开麦克风,需要麦克风权限";
public static final String ERROR_MSG_RECORD_PERMISSION_FAIL = "无法进行录屏,需要录屏权限";
public static final String ERROR_MSG_NO_LOGIN_CACHE = "您的帐号已在其它地方登录";
//播放端错误信息
public static final String ERROR_MSG_GROUP_NOT_EXIT = "直播已结束,加入失败";
public static final String ERROR_MSG_JOIN_GROUP_FAILED = "加入房间失败,Error:";
public static final String ERROR_MSG_LIVE_STOPPED = "直播已结束";
public static final String ERROR_MSG_NOT_QCLOUD_LINK = "非腾讯云链接,若要放开限制请联系腾讯云商务团队";
public static final String ERROR_RTMP_PLAY_FAILED = "视频流播放失败,Error:";
public static final String TIPS_MSG_STOP_PUSH = "当前正在直播,是否退出直播?";
//网络类型
public static final int NETTYPE_WIFI = 0;
public static final int NETTYPE_NONE = 1;
public static final int NETTYPE_2G = 2;
public static final int NETTYPE_3G = 3;
public static final int NETTYPE_4G = 4;
//连麦开关
public static final boolean TX_ENABLE_LINK_MIC = true; //开启连麦标志位
//连麦消息类型
public static final int LINKMIC_CMD_REQUEST = 10001;
public static final int LINKMIC_CMD_ACCEPT = 10002;
public static final int LINKMIC_CMD_REJECT = 10003;
public static final int LINKMIC_CMD_MEMBER_JOIN_NOTIFY = 10004;
public static final int LINKMIC_CMD_MEMBER_EXIT_NOTIFY = 10005;
public static final int LINKMIC_CMD_KICK_MEMBER = 10006;
//连麦响应类型
public static final int LINKMIC_RESPONSE_TYPE_ACCEPT = 1; //主播接受连麦
public static final int LINKMIC_RESPONSE_TYPE_REJECT = 2; //主播拒绝连麦
// UGCEditer
public static final String ACTION_UGC_SINGLE_CHOOSE = "com.tencent.qcloud.xiaozhibo.single";
public static final String ACTION_UGC_MULTI_CHOOSE = "com.tencent.qcloud.xiaozhibo.multi";
public static final String INTENT_KEY_SINGLE_CHOOSE = "single_video";
public static final String INTENT_KEY_MULTI_CHOOSE = "multi_video";
public static final String DEFAULT_MEDIA_PACK_FOLDER = "txrtmp"; // UGC编辑器输出目录
public static final int THUMB_COUNT = 10;
}
完!!!