wx.createInnerAudioContext 在多个音频时,怎么操作其中的某一个音频?
设定2个全局变量
isPlaying:true, // 记录播放状态
PlayingID: playID, //记录播放ID
js
audioPlay(e) {
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = e.detail.target.dataset.src;
let playID = e.detail.target.id;
innerAudioContext.onPlay(() => {
this.setData({
isPlaying:true,
PlayingID: playID
});
});
innerAudioContext.onEnded(() => {
this.setData({
isPlaying: false
});
});
},
wxml
<button id=“Voice{{index}}” data-src="{{ audioUrl }}" class=" {{ isPlaying && PlayingID == (‘Voice’+ index ) ?‘audio-state-playing’:’’}} " formType=“submit”></button>
不清楚的话可以加我的wx号
ginmym