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)
        },
相关推荐
程序员黑豆1 小时前
从零开始:编写第一个鸿蒙(HarmonyOS)程序
前端·harmonyos
lastknight2 小时前
CSS @layer
前端·css
李宸净2 小时前
Web自动化测试selenium+python
前端·python·selenium
淡海水2 小时前
06-04-YooAsset源码-Unity加密解密服务
前端·unity·性能优化·c#·游戏引擎·yooasset
trigger3333 小时前
desk-health-web-community-post
前端
倒流时光三十年3 小时前
Logback 系列(7):常用 Appender(控制台 / 文件 / 滚动文件)
java·前端·logback
谪星·阿凯3 小时前
CTF Web 解题完全指南:从 PHP 弱类型到 SSTI 模板注入的实战方法论
前端·安全·php·ctf web
Csvn3 小时前
页面「穿越」之谜:React 中因 key 值不正确导致的渲染 Bug 排查实战
前端
浅水壁虎3 小时前
前端技术_TypeScript(第一章)
前端