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)
        },
相关推荐
非优秀程序员6 小时前
第10章 千团出世|《互联网产品恩仇录》
前端
非优秀程序员6 小时前
第11章 小高在对面|《互联网产品恩仇录》
前端
非优秀程序员6 小时前
第14章 只剩美团|《互联网产品恩仇录》
前端
非优秀程序员6 小时前
第09章 老乡何必为难老乡|《互联网产品恩仇录》
前端
非优秀程序员7 小时前
第03章 三大门户,烽烟起于瀛海威|《互联网产品恩仇录》
前端
曦樂~11 小时前
【Web Development】02 CSS
前端·css
风骏时光牛马11 小时前
后端服务接口开发与数据逻辑处理
前端
东鹏特饮11 小时前
经典打砖块(Breakout)游戏
前端·css·css3
IT_陈寒11 小时前
Vite的HMR把我整不会了:一个生产环境的热更新坑
前端·人工智能·后端
Mh11 小时前
如何使用双缓冲优化视频切换
前端