纯正商业级应用-微信小程序开发实战 问题

1.音乐播放器模块问题:

相邻的两个资源都是音乐资源的时候,使用wx:if无法再次触发声明周期函数
wxml


index.js

  attached: function() {
    this._recoverPlaying()
    this._monitorSwitch()
  },

改写方法依然使用hidden,同时使用observer监听属性值得改变

index.js

  properties: {
    src: {
      type: String,
      observer: function(newData, oldData) {
        this._recoverStatus()
        this._monitorSwitch()
      }
    },
    title: {
      type: String
    }
  },

2._recoverStatus判断逻辑简化:

仅需要保证:音乐没有暂停且src与当前src相同时 playing为true

    _recoverStatus: function() {
      if (!mMgr.paused && (mMgr.src == this.data.src)) {
        //音乐没有暂停 播放的是当前页面的音乐
        this.setData({
          playing: true,
          rotation: 'rotation'
        })
      } else {
        this.setData({
          playing: false,
          rotation: ''
        })
      }
    },

你可能感兴趣的:(纯正商业级应用-微信小程序开发实战 问题)