收藏
回答

wx.createInnerAudioContext 多个音频

框架类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 wx.createInnerAudioContext 微信iOS客户端 Android 6.6.5 1.9.91

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

回答关注问题邀请回答
收藏

1 个回答

  • 小波
    小波
    2018-03-28

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

    2018-03-28
    有用
    回复
登录 后发表内容