网站建设开发协议,重庆建网站推广价格,国内搜索引擎有哪些,汕头市潮南区紧急提醒需求是#xff1a;进入页面的时候是先有背景音乐#xff0c;发送问题请求回答的时候会返回文字和音频#xff0c;前端要把音频读出来#xff0c;并且把背景音乐停止#xff0c;读完音频后再打开背景音乐
一开始用的直接base64直接拼接在地址后 真机放不了
const innerAu…需求是进入页面的时候是先有背景音乐发送问题请求回答的时候会返回文字和音频前端要把音频读出来并且把背景音乐停止读完音频后再打开背景音乐
一开始用的直接base64直接拼接在地址后 真机放不了
const innerAudioContext wx.createInnerAudioContext();
innerAudioContext.src data:audio/mp3;base64, 请求获取的base64编码的mp3格式文件;
innerAudioContext.play();下面这个方式亲测有效
//背景音乐playBackground(innerAudioContext, stop) {// const innerAudioContext uni.createInnerAudioContext();innerAudioContext.autoplay true;innerAudioContext.loop true; //循环播放innerAudioContext.src https://wealthgod.oss-cn-beijing.aliyuncs.com/caishen/backgroundmq3.mp3;innerAudioContext.onPlay(() {console.log(开始播放);});innerAudioContext.onStop((res) {innerAudioContext.stop()//播放停止销毁该实例innerAudioContext.destroy()});innerAudioContext.onEnded((res) {innerAudioContext.play();});},
//回答音频
playerAnswer(url) {const backgroundAudioManager wx.getBackgroundAudioManager()var number Math.random()const audioPath wx.env.USER_DATA_PATH /new number .mp3const fs wx.getFileSystemManager();fs.writeFile({filePath: audioPath,data: url,encoding: base64,success(res) {backgroundAudioManager.title 财神backgroundAudioManager.src audioPathbackgroundAudioManager.onEnded((res) {backgroundAudioManager.src https://wealthgod.oss-cn-beijing.aliyuncs.com/caishen/backgroundmq3.mp3;});},})},this.playBackground(uni.createInnerAudioContext())this.playerAnswer(surl)//surl是背景地址
//manifest.json中/* 小程序特有相关 */mp-weixin : { requiredBackgroundModes : [ audio ],},