小程序播放器,在iphone上播放不出来
发布于 6 年前 作者 fanggao 8288 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

点击歌曲名之后应该能在一定时间内播放,加载的标志也随之消失,但是却一直在转圈,根据下面的代码,可以得知,开始播放的监听事件一直没有坚挺到,也就是一直都没有开始,但是在开发工具的模拟器中,播放就没有问题。Ps:我家的网络很快

  • 复现路径

    

  • 提供一个最简复现 Demo
playSong:function(e){   
  this.setData({
    songname: e.currentTarget.dataset.songname, //歌曲名称
    songurl: e.currentTarget.dataset.url, //歌曲链接
    currSongIndex: e.currentTarget.dataset.songindex//当前播放的歌曲序号
  });
  this.doMusicPlay();
},
 
doMusicPlay:function(){
  wx.showLoading({
    title: '加载中'
  });
  const backgroundAudioManager = wx.getBackgroundAudioManager()
  backgroundAudioManager.title = this.data.songname;
  backgroundAudioManager.epname = this.data.folder.name;
  backgroundAudioManager.singer = this.data.singer;
  backgroundAudioManager.coverImgUrl = this.data.folder.pic;
  // 设置了 src 之后会自动播放
  backgroundAudioManager.src = this.data.songurl;
  // 开始播放音乐的监听事件
  backgroundAudioManager.onCanplay(function () {
    wx.hideLoading();
  })
  //监听音乐正常播放完的事件,顺序循环
  let that = this;
  backgroundAudioManager.onEnded(() => {
    let songlist = that.data.songs;
    let listlength = songlist.length;
    let currsongIndex = that.data.currSongIndex;
 
    let nextsongIndex = (currsongIndex + 1) % listlength;
    let nextsong = songlist[nextsongIndex];
    that.setData({
      currSongIndex: nextsongIndex,//当前播放的歌曲序号
      songtitle: nextsong.name,
      songurl: nextsong.url
    });
    //列表循环
    that.doMusicPlay();
  })
}
1 回复

报错信息是什么呢?麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部