小程序-音乐播放器 showActionSheet的使用

小程序实现简单的音乐播放功能:

1,showActionSheet显示下侧弹窗效果

2,wx.playBackgroundAudio实现音乐播放

先看实现的效果:


代码如下:

 showAction:function(){
    wx.showActionSheet({
      itemList: this.data.items,
      success: function (res) {
        console.log(res.tapIndex)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  itemClick:function(e){
    console.log(e);
    var position=e.target.id;
    console.log(position);
    var imgurl=this.data._songsList[position].coverImgUrl;
    var name = this.data._songsList[position].name;
    var dataUrl = this.data._songsList[position].dataUrl;
    console.log(this.data._songsList[position]);
    this.setData({
      currentImage: imgurl,
      currentName: name
    });
    //播放音乐
    wx.playBackgroundAudio({
      dataUrl: dataUrl,
      title: name,
      coverImgUrl: imgurl
    })
  }
demo下载地址

猜你喜欢

转载自blog.csdn.net/qq_35828720/article/details/80704664