小程序
小游戏
企业微信
微信支付
扫描小程序码分享
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(() => {
isPlaying: false
},
wxml
<button id="Voice{{index}}" data-src="{{ audioUrl }}" class=" {{ isPlaying && PlayingID == ('Voice'+ index ) ?'audio-state-playing':''}} " formType="submit"></button>
不清楚的话可以加我的wx号
ginmym
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
设定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