uniapp 如何调用音频

uniapp调用音频

button点击

powershell 复制代码
       <view>
       <button @click="startPlay">开始播放</button>
       </view>

方法实现

powershell 复制代码
  startPlay() {  
      const innerAudioContext = uni.createInnerAudioContext();
      innerAudioContext.src = '/static/sounds/oqc.mp3';
      innerAudioContext.play()
       }

自定义播放 本地调试可以 打包 APK调用失败(需补充使用)

powershell 复制代码
  startPlay() {  
     this.a(); // 开始播放的入口 
     },  
     a(){

         var time = new Date();
          console.log('time:',time)
          const asd = '请001号前来办理业务'
          const msg = new SpeechSynthesisUtterance()
          msg.text = asd
          let that = this
          msg.onend = function(){
            that.count+=1
            // alert('播放结束')
            setTimeout(function(){
          that.play()

            },1000)
          }
          window.speechSynthesis.speak(msg)
    },
     play(){
          console.log('this.count',this.count)
          if(this.count < 3){
            this.a()
          }else{
            this.count = 0
            console.log('播放完毕')
          }
          // setInterval(this.cyclePlay(),1000)
        },
相关推荐
IT_陈寒11 小时前
Vue这个动态响应坑把我整不会了
前端·人工智能·后端
bestlanzi11 小时前
使用nvm管理node环境
前端·vue.js·npm
SomeOtherTime11 小时前
Geojson相关(AI回答)
java·前端·python
阿洛学长12 小时前
MoneyPrinterTurbo 深度解析与部署实战:AI 一键短视频生成,从源码到上线全攻略
人工智能·音视频
就叫_这个吧12 小时前
HTML常用标签及举例使用
前端·html
utf8mb4安全女神12 小时前
【rsyslog服务】把所有服务的“临界点”以上的错误都保存在/var/log/alert.log⽇志中
java·前端·javascript
YANQ66213 小时前
7.bundlesdf本地安装
前端·webpack·node.js
星夜夏空9913 小时前
FreeRTOS学习(7)——任务列表
java·前端·学习
weixin_4713830313 小时前
由浅入深递归练习
前端·javascript·vue.js
tedcloud12313 小时前
ai-engineering-from-scratch部署教程:从零搭建AI应用环境
服务器·前端·人工智能·系统架构·edge