美文网首页
wx.createInnerAudioContext()//微信

wx.createInnerAudioContext()//微信

作者: 在下高姓 | 来源:发表于2020-06-17 16:13 被阅读0次
微信官方文档audio 组件不再维护,不知道是我调用的姿势不对,还是真的不能用了,根据官方推荐使用wx.createInnerAudioContext()
1.全局声明wx.createInnerAudioContext()---局部声明的话会出现播放后不能调用暂停事件
const innerAudioContext=wx.createInnerAudioContext();
2.局部调用
click(){
      innerAudioContext.src=this.properties.tempFilePath;//播放的src
      if(this.data.status==true){//奇数点击
        this.setData({//动画开关
          open:true,
          status:false,
        })
        innerAudioContext.play();//播放

      }else{//偶数点击
        innerAudioContext.stop();//暂停
        this.setData({
          open:false,
          status:true
        })
      }
      innerAudioContext.onEnded((res)=> {//监听播放结束
        this.setData({
          open:false,
          status:true
        })
        console.log("监听播放结束")
  })
},

相关文章

网友评论

      本文标题:wx.createInnerAudioContext()//微信

      本文链接:https://www.haomeiwen.com/subject/laysxktx.html