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)
        },
相关推荐
EasyCVR2 小时前
智能守护校园:视频汇聚平台EasyCVR如何构建校园消防安全新防线
音视频
编程社区管理员3 小时前
React 发送短信验证码和验证码校验功能组件
前端·javascript·react.js
全马必破三3 小时前
React“组件即函数”
前端·javascript·react.js
三思而后行,慎承诺3 小时前
React 底层原理
前端·react.js·前端框架
座山雕~3 小时前
html 和css基础常用的标签和样式
前端·css·html
灰小猿4 小时前
Spring前后端分离项目时间格式转换问题全局配置解决
java·前端·后端·spring·spring cloud
im_AMBER4 小时前
React 16
前端·笔记·学习·react.js·前端框架
02苏_4 小时前
ES6模板字符串
前端·ecmascript·es6
excel4 小时前
⚙️ 一次性警告机制的实现:warnOnce 源码深度解析
前端
excel4 小时前
Vue SFC 样式编译核心机制详解:compileStyle 与 PostCSS 管线设计
前端