【毕业设计】小程序的问题集合及解决方法

209 阅读1分钟

1 播放背景音频的新API :wx.getBackgroundAudioManager()

  data: {
    // 对象初始化一般用null
    backgroundAudioManager: null
  },
  pauseBgm() {
    // 调用data中的数据记得前缀
    this.data.backgroundAudioManager.pause()
  },
  onLoad: function (options) {
    const backgroundAudioManager = wx.getBackgroundAudioManager()
    // 为了方便事件调用暂停、播放、停止等方法
    this.setData({
      backgroundAudioManager: backgroundAudioManager
    })
    // 配置信息,转发等都会显示出来
    backgroundAudioManager.title = '说好不哭'
    backgroundAudioManager.epname = '说好不哭'
    backgroundAudioManager.singer = '周杰伦'
    backgroundAudioManager.coverImgUrl = 'https://y.gtimg.cn/music/photo_new/T002R300x300M000000Eytsu48dRJP.jpg?max_age=2592000'
    // 设置了 src 之后会自动播放
    backgroundAudioManager.src = 'http://www.krislee.xyz/mini/testCry.mp3'
  },

1.1 小程序后台继续播放背景音乐操作

  "pages": [
    "pages/disc/disc",
    ···
  ],
    // 在 app.json 中增加一项配置,
  "requiredBackgroundModes": [
    "audio"
  ]