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)
        },
相关推荐
徐小夕20 分钟前
jitword 协同文档3.2发布:打造浏览器中最强word编辑器
前端·架构·github
纯爱掌门人2 小时前
干了这么多年前端,聊聊 2026 年我们到底还值不值钱
前端·程序员
houhou2 小时前
Monaco Editor 集成指南:从配置到优化
前端
hunterandroid2 小时前
[Android 从零到一] Custom View 自定义绘制:从 onDraw 到完整交互
前端
李明卫杭州2 小时前
Vue3 v-memo 指令详解:让你的列表渲染性能翻倍 🚀
前端
梨子同志2 小时前
Monorepo
前端
lihaozecq2 小时前
继 Web Coding Agent 后,我做了一个本地优先的桌面 AI Agent
前端·agent
用户298698530142 小时前
在 React 中使用 JavaScript 将 Excel 转换为 SVG
前端·javascript·react.js
CodingSpace3 小时前
ESLint
前端
Csvn3 小时前
异步错误捕获的六大陷阱:await 裹着 try-catch 就一定稳了吗?
前端