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)
        },
相关推荐
|晴 天|3 小时前
Vue 3 + TypeScript + Element Plus 博客系统开发总结与思考
前端·vue.js·typescript
猫3284 小时前
v-cloak
前端·javascript·vue.js
旷世奇才李先生4 小时前
Vue 3\+Vite\+Pinia实战:企业级前端项目架构设计
前端·javascript·vue.js
SoaringHeart5 小时前
Flutter进阶:用OverlayEntry 实现所有弹窗效果
前端·flutter
有味道的男人6 小时前
电商效率翻倍:用 Open Claw 对接小红书视频详情接口,一键抓取商品全量信息
音视频
IT_陈寒7 小时前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace7 小时前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常8 小时前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o8 小时前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端8 小时前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试