拍卖小程序直播功能扩展之翻转摄像头、美颜

一、获取当前页面

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
			);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值