收藏
回答

wx.getBackgroundAudioManager()无法赋值

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.getBackgroundAudioManager 微信iOS客户端 8.0.16 2.20

回答关注问题邀请回答
收藏

2 个回答

  • Demons
    Demons
    2022-01-05

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2022-01-05
    有用
    回复
  • 第57个民族-上班族
    第57个民族-上班族
    2022-01-05
      <image src="https://qiniu-image.qtshe.com/20210719music.png" class="music-icon {{start ? '' : 'active'}}" bindtap="handleProxy" />
    
    
    onReady() {
        this.back = wx.getBackgroundAudioManager()
        // 对实例进行设置
        this.back.src = "https://qiniu-video.qtshe.com/qtshe.mp3"
        this.back.title = '青团社8周年庆' // 标题为必选项
        this.back.play() // 开始播放
        // 1、onEnded监听播放自然结束
        this.back.onEnded(() => {
          // 2、必须重新设置src才能循环之后会重新自动播放
          this.back.src = "https://qiniu-video.qtshe.com/qtshe.mp3"
        })
        this.back.onStop((res) => {
          this.setData({ start: !this.data.start })
          this.close = true
          this.back.pause();
        })
      },
    
    
      handleProxy() {
        this.back.pause(); // 点击音乐图标后出发的操作
        this.setData({ start: !this.data.start })
        if (this.data.start) {
          if (this.close) {
            this.close = false
            this.back.src = "https://qiniu-video.qtshe.com/qtshe.mp3"
          } else {
            this.back.play();
          }
          console.log("背景音乐已开启");
        } else {
          this.back.pause();
          console.log("背景音乐已暂停");
        }
      },
    
    2022-01-05
    有用
    回复
登录 后发表内容