小程序 实时音视频live-player、实时音视频录制live-pusher、多人音视频对话voip-room

都需要先通过类目审核,再在小程序管理后台,「开发」-「接口设置」中自助开通该组件权限。

1、实时音视频live-player
	<live-player src="https://domain/pull_stream" mode="RTC" autoplay bindstatechange="statechange" binderror="error" style="width: 300px; height: 225px;" />
	
	const LivePlayerContext = wx.createLivePlayerContext('组件id',在自定义组件下当前组件实例的this)
	方法
		LivePlayerContext.play()
		播放
		LivePlayerContext.stop()
		停止
		LivePlayerContext.mute()
		静音
		LivePlayerContext.pause()
		暂停
		LivePlayerContext.resume()
		恢复
		LivePlayerContext.requestFullScreen(Object object)
		进入全屏
		LivePlayerContext.exitFullScreen()
		退出全屏
		LivePlayerContext.exitPictureInPicture()
		退出小窗,该方法可在任意页面调用
		LivePlayerContext.snapshot(Object object)
		截图
		LivePlayerContext.requestPictureInPicture()
		进入小窗
	
2、实时音视频录制live-pusher
	<live-pusher url="https://domain/push_stream" mode="RTC" autopush bindstatechange="statechange" style="width: 300px; height: 225px;" />
	
	const LivePusherContext = wx.createLivePusherContext()
	
	方法
		LivePusherContext.start()
		开始推流,同时开启摄像头预览
		LivePusherContext.stop()
		停止推流,同时停止摄像头预览
		LivePusherContext.pause()
		暂停推流
		LivePusherContext.resume()
		恢复推流
		LivePusherContext.switchCamera()
		切换前后摄像头
		LivePusherContext.snapshot(Object object)
		快照
		LivePusherContext.toggleTorch()
		切换手电筒
		LivePusherContext.playBGM(Object object)
		播放背景音
		LivePusherContext.stopBGM()
		停止背景音
		LivePusherContext.pauseBGM()
		暂停背景音
		LivePusherContext.resumeBGM()
		恢复背景音
		LivePusherContext.setBGMVolume(Object object)
		设置背景音音量
		LivePusherContext.setMICVolume(Object object)
		设置麦克风音量
		LivePusherContext.startPreview()
		开启摄像头预览
		LivePusherContext.stopPreview()
		关闭摄像头预览
		LivePusherContext.sendMessage(Object object)
		发送SEI消息
	
3、voip-room多人音视频对话(先通过类目审核,再在小程序管理后台,「开发」-「接口设置」中自助开通该组件权限)
	每个房间最多同时加入10个人,每天最多允许创建100000个房间,当所有人退出房间时,房间即被销毁,此时如果传入之前用过的groupId重新加入房间,会被计算为新开一个房间。
	
	每个人对应一个视频块
	<block wx:for="{{openIdList}}" wx:key="*this">
	  <voip-room
	    openid="{{item}}"		进入房间用户的openid
	    mode="{{selfOpenId === item ? 'camera' : 'video'}}">	对话窗口类型,自身传入camera,其它用户传入 video
	    device-position='front'	仅在mode为camera时有效,前置或后置,值为front, back
	    binderror				创建对话窗口失败时触发
	  </voip-room>
	</block>

	(1)获取加入房间的openid
		wx.joinVoIPChat({
			roomType			房间类型
				voice	音频房间,用于语音通话	
				video	视频房间,结合voip-room组件可显示成员画面
			signature			签名,用于验证身份,详见签名算法
			nonceStr			验证所需的随机字符串
			timeStamp			验证所需的时间戳
			groupId				小游戏内此房间/群聊的ID,同一时刻传入相同groupId的用户会进入到同个实时语音房间。
				groupId由开发者设置并保持唯一
			muteConfig			静音设置
				muteMicrophone是否静音麦克风
				muteEarphone 是否静音耳机
			success				接口调用成功的回调函数
				openIdList在此通话中的成员openId名单
			fail				接口调用失败的回调函数
				-1	当前已在房间内	
				-2	录音设备被占用,可能是当前正在使用微信内语音通话或系统通话	
				-3	加入会话期间退出(可能是用户主动退出,或者退后台、来电等原因),因此加入失败	
				-1000	系统错误
			complete			接口调用结束的回调函数(调用成功、失败都会执行)
		})
		
		签名算法:
			signature = hmac_sha256([appId, groupId, nonceStr, timeStamp].sort().join(''), sessionKey)
				hmac_sha256需要开发者自行引入
		示例:
			方式一:
				appId = 'wx20afc706a711eefc'
				groupId = '1559129713_672975982'
				nonceStr = '8AP6DT9ybtniUJfb'
				timeStamp = '1559129714'
				session_key = 'gDyVgzwa0mFz9uUP7M6GQQ=='
				
				str = [appId, groupId, nonceStr, timeStamp].sort().join('') = '1559129713_67297598215591297148AP6DT9ybtniUJfbwx20afc706a711eefc'
				signature = hmac_sha256('1559129713_67297598215591297148AP6DT9ybtniUJfbwx20afc706a711eefc', sessionKey) = 'b002b824688dd8593a6079e11d8c5e8734fbcb39a6d5906eb347bfbcad79c617'
				
			方式二:使用云开发生成签名
				const cloud = require('wx-server-sdk')
				cloud.init()
				
				exports.main = async (event, context) => {
				  const signature = cloud.getVoIPSign({
				    groupId: 'xxx',
				    timestamp: 123,
				    nonce: '随机字符串'
				  })
				  return signature
				}
				
	(2)进入房间后的监控api
		离开房间:
			wx.exitVoIPChat({
				success,
				fail,
				complete
			})
		更新房间麦克风/耳机静音设置:
			wx.updateVoIPChatMuteConfig({
				muteConfig
					muteMicrophone是否静音麦克风
					muteEarphone 是否静音耳机
				,
				...
			})
			
		监听房间状态变化事件:
			wx.onVoIPChatStateChanged(function callback)
			wx.offVoIPChatStateChanged(function callback)	取消监听房间状态变化事件
			
		监听房间成员变化:
			wx.onVoIPChatMembersChanged({
				openIdList	还在实时语音通话中的成员 openId 名单
				errCode		错误码
				errMsg		调用结果
			})
			wx.offVoIPChatMembersChanged(function callback)	取消监听实时语音通话成员在线状态变化事件
		监听房间成员通话状态变化:
			wx.onVoIPChatSpeakersChanged({
				openIdList	还在实时语音通话中的成员 openId 名单
				errCode		错误码
				errMsg		调用结果
			})
		监听通话中断:
			包括切入后端时断开
			wx.onVoIPChatInterrupted({
				errCode		错误码
				errMsg		调用结果
			})
			wx.offVoIPChatInterrupted(function callback)	取消监听被动断开实时语音通话事件
		监听实时语音通话成员视频状态变化:
			wx.onVoIPVideoMembersChanged({
				openIdList	还在实时语音通话中的成员openId名单
				errCode		错误码
				errMsg		调用结果
			})
			wx.offVoIPVideoMembersChanged(function callback)	取消监听实时语音通话成员视频状态变化事件
		订阅视频画面成员:
			订阅视频画面成员。对于视频房间,当成员超过两人时需进行订阅,否则只能看到最先加入房间的两人画面。
			wx.subscribeVoIPVideoMembers({
				openIdList	订阅的成员列表
				...
			})
		
		开启双人通话:
			设置enable为false时,无法接听呼叫
			wx.setEnable1v1Chat(Object object)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值