wx.createInnerAudioContext 多个音频

发布于 6 年前作者 na061693 次浏览最后编辑 6 年前来自 ask

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

1 回复
guping
guping1 楼5 年前

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