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)
        },
相关推荐
南雨北斗16 分钟前
vue3项目中的env.d.ts文件
前端
烈风逍遥24 分钟前
第五篇:通用 LLM 流式对话:前后端联接的完整实现
前端·后端·架构
aixingpan25 分钟前
aixingpan.cn API开发文档:api_docs_trichart_natal_progression_sec_transit2接口指南
前端·php
江华森36 分钟前
Web 安全实战:验证机制、会话管理、SQL 注入、XSS 与 CSRF
前端
江华森42 分钟前
HTTPS 实战:TLS 握手成本、自制 CA 与证书、三大常见故障
前端
江华森1 小时前
HTTP 再邂逅:报文结构、请求方法、状态码与 Cookie/Session
前端
szephyr1 小时前
前端错误监控实战:用 Sentry 把线上报错从“用户反馈“变成“主动发现“
前端·sentry·稳定性·前端监控·错误监控
拖孩1 小时前
给小程序加「一键发公众号贴图」,我把 wx.shareToOfficialAccount 的三个坑趟了一遍
前端·后端·微信小程序
ONLYOFFICE1 小时前
团队协作软件指南:主要类型、核心功能、选型建议等
前端·onlyoffice·office