attached: function () {
this.musicaudio()
},
methods: {
music: function (e) {
var music1 = this.data.music
this.setData
({
music:! music1
})
},
musicaudio: function () {
var that = this
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.src = that.data.musicsong.src
if(that.data.music){
innerAudioContext.play();
console.log(‘start’)
}
else{
innerAudioContext.pause();
console.log(‘pause’)
}
innerAudioContext.onPlay(() => {
console.log(“播放”);
})
innerAudioContext.onPause(() => {
console.log(“暂停”);
})
}
组件中调用,代码如上,组件加载后自动播放音乐,点击按钮可以暂停音乐播放,可是控制台输出了pause
音乐却没有暂停,不知道为什么?