txLivex
addEventListener
setLicence
getLicence
setUgcLicence
getUgcLicence
push
startPush
stopPush
player
startPlayer
stopPlayer
setMusicUrl
setEditConfig
record
picker
论坛示例
为帮助用户更好更快的使用模块,论坛维护了一个示例,示例中包含示例代码、知识点讲解、注意事项等,供您参考。
概述
txLivex腾讯云视频推流 拉流 录制 编辑 合成 美颜 图片转场
模块概述
1.视频推流 插屏 2.视频拉流 插屏 3.视频录制 合唱 三屏录制 背景音乐 美颜 特效 4.视频合成 相册选择 视频 图片 合成 编辑
温馨提示
监听统一接口
ox.addEventListener(function(ret) {
var code= ret.code;
// 0 返回按钮点击
// -1 地址不合法
// -2 网络不好 chorus下载失败
// -5 证书错误
// 1 ret.progress chorus下载进度
// 8 返回视频结果videoPath coverPath 关闭录制ui
}
});
模块接口
addEventListener
监听统一接口
addEventListener(callback)
返回格式
code 值代表放回 事件 请参考 上面 温馨提示
示例代码
ox.addEventListener(function(ret) {
var code= ret.code;
});
);
可用性
Android,ios系统
可提供的1.0.0
setLicence
设置直播推流licence 请到腾讯云官方申请
setLicence({param})
示例代码
var txLivex = api.require('txLivex');
txLivex.setLicence({
licenceURL:'http://license.vod2.myqcloud.com/license/v1/846013fb247600a451e1f95e26706ee7/TXLiveSDK.licence',
licenceKey:'976ec4ea20395531353f5db330f36f31'
},function(ret) {
//code 0 成功
var code = ret.code;
alert(ret.text);
});
可用性
Android,ios系统
可提供的1.0.0
getLicence
获取直播推流licence
getLicence(callback)
示例代码
var txLivex = api.require('txLivex');
txLivex.getLicence(function(ret) {
//code 0 成功
var code = ret.code;
alert(ret.licence);
});
可用性
Android,ios系统
可提供的1.0.0
setUgcLicence
设置小视频录制licence 请到腾讯云官方申请
setUgcLicence({param})
示例代码
var txLivex = api.require('txLivex');
txLivex.setUgcLicence({
licenceURL:'http://license.vod2.myqcloud.com/license/v1/846013fb247600a451e1f95e26706ee7/TXUgcSDK.licence',
licenceKey:'976ec4ea20395531353f5db330f36f31'
},function(ret) {
//code 0 成功
var code = ret.code;
alert(ret.text);
});
可用性
Android,ios系统
可提供的1.0.0
getUgcLicence
获取小视频录制licence
getUgcLicence(callback)
示例代码
var txLivex = api.require('txLivex');
txLivex.getUgcLicence(function(ret) {
//code 0 成功
var code = ret.code;
alert(ret.licence);
});
可用性
Android,ios系统
可提供的1.0.0
push
开启推流
示例代码
var playBtn,cameraSwitchBtn,beautyBtn,bgmBtn,logBtn,settingBtn,moreBtn;
playBtn = {
type: 'playBtn',
x: 10,
y: h - 60,
w: 45,
h: 45,
code: 11,
hidden: false
};//播放按钮
cameraSwitchBtn = {
type: 'cameraSwitchBtn',
x: 65,
y: h - 60,
w: 45,
h: 45,
code: 12,
hidden: false
};//前后摄像头切换按钮
beautyBtn = {
type: 'beautyBtn',
x: 120,
y: h - 60,
w: 45,
h: 45,
code: 13,
hidden: false
};//美颜按钮
bgmBtn = {
type: 'bgmBtn',
x: 175,
y: h - 60,
w: 45,
h: 45,
code: 14,
hidden: false
};//音乐按钮
logBtn = {
type: 'logBtn',
x: 230,
y: h - 60,
w: 45,
h: 45,
code: 15,
hidden: false
};//日志按钮
settingBtn = {
type: 'settingBtn',
x: 285,
y: h - 60,
w: 45,
h: 45,
code: 16,
hidden: false
};//设置按钮
moreBtn = {
type: 'moreBtn',
x: 340,
y: h - 60,
w: 45,
h: 45,
code: 17,
hidden: false
};//更多按钮
var styles = [playBtn,cameraSwitchBtn,beautyBtn,bgmBtn,logBtn,settingBtn,moreBtn];
txLivex.push({
rect:{x:0, y:0,w:'auto', h:'auto'},
fixedOn:api.frameName,
fixed:true,
showBack:true,//默认true 隐藏返回按钮
autoPush:true,//默认true //是否打开界面自动开启推流
front:false,//默认是否前置摄像头
watermark:'widget://image/img_find_default.png',//水印暂时不生效
styles:styles,
musicUrl:'http://dldir1.qq.com/hudongzhibo/LiteAV/demomusic/testmusic3.mp3',//背景音乐
url:'rtmp://104855.livepush.myqcloud.com/live/jiang?txSecret=c1d95dae2d5b0cbde0301c9748f48862&txTime=5EFD5D61'
});
可用性
Android,ios系统
可提供的1.0.0
startPush
开始推流
示例代码
txLivex.startPush();
可用性
Android,ios系统
可提供的1.0.0
stopPush
停止推流
示例代码
txLivex.stopPush();
可用性
Android,ios系统
可提供的1.0.0
player
拉流播放器
示例代码
var playBtn,logBtn,hwDecodeBtn,orientationBtn,renderModeBtn,cacheBtn;
playBtn = {
type: 'playBtn',
x: 10,
y: h - 60,
w: 45,
h: 45,
code: 11,
hidden: false
};//播放按钮
logBtn = {
type: 'logBtn',
x: 65,
y: h - 60,
w: 45,
h: 45,
code: 12,
hidden: false
};//日志按钮
hwDecodeBtn = {
type: 'hwDecodeBtn',
x: 120,
y: h - 60,
w: 45,
h: 45,
code: 13,
hidden: false
};//硬编码按钮
orientationBtn = {
type: 'orientationBtn',
x: 175,
y: h - 60,
w: 45,
h: 45,
code: 14,
hidden: false
};//旋转方向按钮
renderModeBtn = {
type: 'renderModeBtn',
x: 230,
y: h - 60,
w: 45,
h: 45,
code: 15,
hidden: false
};//显示比例按钮
cacheBtn = {
type: 'cacheBtn',
x: 285,
y: h - 60,
w: 45,
h: 45,
code: 16,
hidden: false
};//缓存策略按钮
var styles = [playBtn,logBtn,hwDecodeBtn,orientationBtn,renderModeBtn,cacheBtn];
// code值
// 0 返回按钮事件
txLivex.addEventListener(function(ret) {
var code = ret.code;
if(code == 0){
api.closeWin();
}else if(code == -1){
//地址不合法
}else if(code == -5){
//播放错误
}
});
txLivex.player({
rect:{x:0, y:0,w:'auto', h:'auto'},
fixedOn:api.frameName,
fixed:true,
showBack:true,//默认true 隐藏返回按钮
autoPlay:true,//默认true //是否自动播放
styles:styles,
url:'http://5815.liveplay.myqcloud.com/live/5815_89aad37e06ff11e892905cb9018cf0d4_900.flv'
});
可用性
Android,ios系统
可提供的1.0.0
startPlayer
开始播放
示例代码
txLivex.startPlayer();
可用性
Android,ios系统
可提供的1.0.0
stopPlayer
停止播放
示例代码
txLivex.stopPlayer();
可用性
Android,ios系统
可提供的1.0.0
setMusicUrl
设置全局音乐列表地址
示例代码
url 音乐数据格式
{
"bgm": {
"list": [{
"name": "11111",
"url": "http://dldir1.qq.com/hudongzhibo/LiteAV/demomusic/testmusic1.mp3"
}, {
"name": "22222",
"url": "http://dldir1.qq.com/hudongzhibo/LiteAV/demomusic/testmusic2.mp3"
}, {
"name": "33333",
"url": "http://dldir1.qq.com/hudongzhibo/LiteAV/demomusic/testmusic3.mp3"
}
]
}
}
txLivex.setMusicUrl({musicUrl:'widget://music/bgm_list.json'},function(ret) {
//code 0 设置成功
var code = ret.code;
alert(ret.text);
});
可用性
Android,ios系统
可提供的1.0.0
setEditConfig
视频编辑常用配置
示例代码
txLivex.setEditConfig({
resolution:2,//分辨率 0 360p 1 480p 2 540p 3 720p 默认 540p
videoBitrate:6500,//mbps 默认 6500
isCoverGenerate:true,//是否生成封面,默认为true
isSaveToDCIM:true,//是否保存到相册,默认为true
isPublish:true,//是否需要发布视频
watermark:{path:'widget://image/img_find_default.png',x:200,y:320,w:120,h:40},//视频水印 path 一定要以widget开头
tailwatermark:{path:'widget://image/img_find_default.png',x:200,y:420,w:120,h:40,duration:5}//片尾水印 path 一定要以widget开头
},function(ret) {
//code 0 设置成功
var code = ret.code;
alert(ret.text);
});
可用性
Android,ios系统
可提供的1.0.0
record
视频录制
示例代码
txLivex.addEventListener(function(ret) {
//code 0 取消返回按钮事件 -1失败 -2 失败 8 编辑结束返回视频信息
var code = ret.code;
if(code==-1){
alert(ret.text);
}else if(code==-2){
//chorus下载失败
alert(ret.text);
}else if(code==0){
api.closeWin();
}else if(code==1){
//ret.progress chorus下载进度
}else if(code==8){
//返回视频结果videoPath coverPath 关闭录制ui
alert(JSON.stringify(ret))
api.closeWin();
}
});
txLivex.record({
rect:{x:0, y:0,w:'auto',h:'auto'},
fixedOn:api.frameName,
fixed:true,
config:{
recordStyle : 1,//0 纯录制模式 1 分屏合拍模式 2 三屏合拍模式 (1 2 模式下其他设置不生效 需要chorusUrl 合并视频地址)
chorusUrl:'http://1400100725.vod2.myqcloud.com/8b7d5993vodgzp1400100725/d864a3545285890780576877210/ss2W2I8oIn4A.mp4',
minDuration : 5000,//视频最短时长
maxDuration : 15000,//视频最长时长
aspectRatio : 0,//屏比(0 9*16 1 3*4 2 1*1 3 16*9 4 4*3)
recommendQuality : -1,//0 底 1 中等 2 高 android 有效
resolution : 1,//录制分辨率(0 360P 1 540P 2 720P 3 1080P)
videoBitrate : 9600,//码率 单位kbps/s 默认值:9600
fps : 20,//帧率 范围:(15-30)默认值:20
gop : 3,//关键帧间隔 范围:(1-10) 默认值:3
orientation : 1,//录制方向(0 right 1down 2left 3 up)
touchFocus : true,//自动聚焦
needEdit : true,//是否需要编辑
isFront : true//是否前置摄像头
}
});
可用性
Android,ios系统
可提供的1.0.0
picker
选择器 视频合成
示例代码
txLivex.addEventListener(function(ret) {
var code = ret.code;
//videoPath coverPath
if(code==8){
alert(JSON.stringify(ret))
}
});
txLivex.picker({
type:0, //0选择视频合成 1 选择图片合成
});
可用性
Android,ios系统
可提供的1.0.0