uniapp监听到推送就播放语音

uniapp yekong

uniapp需要一个功能,监听到推送并播放语音,这需要receive,使用receive需要透传

import src from '@/static/mp3/msg.mp3'
	export default {
		onLaunch: function() {
			console.log(plus.push.getClientInfo().clientid)
			//#ifdef APP-PLUS
			plus.push.addEventListener(
				'receive',
				(msg) => {
					// 这是接收的内容
					console.log('recevice:' + JSON.stringify(msg))
					// 这里获取后端传来的参数
					console.log(JSON.parse(msg.content))
					// 这里可以写跳转逻辑代码
					const Audio = uni.createInnerAudioContext();
					Audio.autoplay = true;
					Audio.src = src; //音频地址  
					Audio.play(); //执行播放  
					Audio.onError((res) => {
						console.log(res.errMsg);
						console.log(res.errCode);
					});
					Audio.onPause(function() {
						console.log('end');
						Audio.destroy();
					});
				},
				false
			)
			/* 5+  push 消息推送 ps:使用:H5+的方式监听,实现推送*/
			plus.push.addEventListener(
				'click',
				(msg) => {
					console.log('click:' + JSON.stringify(msg))
					/**
					 *  推送的标题/名字和内容
					 *  payload:{"title":"碎碎z","content":"聊天内容"}
					 */
					console.log(msg.payload)
				},
				false
			)

			//#endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide');
		},
	};
喜欢