一、获取当前页面
var pages = getCurrentPages();
var page = pages[pages.length - 1];
// #ifdef APP-PLUS
var getcurrentWebview = page.$getAppWebview();
this.plusReady(getcurrentWebview); //创建LivePusher对象
// #endif
二、创建LivePusher对象
plusReady(currentWebview) {
var pusher = new plus.video.LivePusher('pusher', {
url: '',
top: '0px',
left: '0px',
width: '100%',
// mode: 'SD',推流视频模式,可取值:SD(标清), HD(高清), FHD(超清)
height: '100%',
position: 'absolute', //static静态布局模式,如果页面存在滚动条则随窗口内容滚动,absolute绝对布局模式,如果页面存在滚动条不随窗口内容滚动; 默认值为"static"
beauty: '0', //美颜 0 关 1 开
whiteness: '0', //0、1、2、3、4、5,0不使用美白,值越大美白程度越大。
aspect: '9:16'
});
}
三、摄像头翻转功能
// 创建镜头切换的按钮
var that = this;
var switchBarVew = new plus.nativeObj.View(
'switchBarVew',
{
top: '5%',
left: '80%',
height: '10%',
width: '20%'
},
[
{
tag: 'img',
id: 'reversal',
src: '图片本地路径',
position: {
width: '28%',
left: '36%',
height: '30%'
}
},
{
tag: 'font',
id: 'font',
text: '翻转',
textStyles: {
size: '10px',
color: '#ffffff'
},
position: {
width: '80%',
left: '10%'
}
}
]
);
// ios必须要加这个,不然ios会白屏
pusher.preview();
//将创建的直播推流与翻转按钮对象 追加到webview中
currentWebview.append(pusher);
currentWebview.append(switchBarVew);
switchBarVew.addEventListener('click',function(e) {
pusher.switchCamera();
},false);
四、直播美颜功能
// 创建美颜按钮
var beautyBarVew = new plus.nativeObj.View(
'beautyBarVew',
{
top: '15%',
left: '80%',
height: '10%',
width: '20%'
},
[
{
tag: 'img',
id: 'reversal',
src: '图片本地路径',
position: {
width: '28%',
left: '36%',
height: '30%'
}
},
{
tag: 'font',
id: 'font',
text: '美颜-关',
textStyles: {
size: '10px',
color: '#ffffff'
},
position: {
width: '80%',
left: '10%'
}
}
]
);
//将创建的美颜对象 追加到webview中
currentWebview.append(beautyBarVew);
//给美颜按钮添加点击事件
beautyBarVew.addEventListener(
'click',
function(e) {
temp.beauty=!that.beauty;
var textT='';
var srcPath='';
var colors='';
if(temp.beauty){
textT='美颜-开';
srcPath='图片本地路径';
pusher.setStyles({
beauty:1 //beauty为1打开美颜效果
})
colors='#f4ea2a';
}else{
textT='美颜-关';
srcPath='图片本地路径';
pusher.setStyles({
beauty:0 //beauty为0关闭美颜效果
})
colors='#ffffff';
}
beautyBarVew.draw([
{
tag: 'img',
id: 'reversal',
src: srcPath,
position: {
width: '28%',
left: '36%',
height: '30%'
}
},
{
tag: 'font',
id: 'font',
text: textT,
textStyles: {
size: '10px',
color: colors
},
position: {
width: '80%',
left: '10%'
}
}
]);
},
false
);