play: function () {
var that = this
backgroundAudioManager.src = this.data.musicitem[this.data.index].url
backgroundAudioManager.play()
backgroundAudioManager.onPlay( function(){
var maxnum = Math.floor(backgroundAudioManager.duration)
that.setData({ maxnum })
console.log(that.data.maxnum)
})
backgroundAudioManager.onEnded(function () {
that.next()
})
},
如代码backgroundAudioManager.onPlay( function(){})中先给了url播放地址然后在播放事件中获取音频长度,获取到为0。在控制台输入wx.getBackgroundAudioManager().duration 后能获取到音频长度,也就是说获取音频长度的代码在给定url和播放之前执行了。为什么写在播放时间中,依旧获取不到??