wx.createInnerAudioContext 多个音频
发布于 5 年前 作者 na06 1519 次浏览 来自 问答

wx.createInnerAudioContext 在多个音频时,怎么操作其中的某一个音频?

1 回复

设定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

回到顶部