收藏
回答

小程序播放器,在iphone上播放不出来

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.getBackgroundAudioManager() 工具 7.0.3 2.2.6

- 当前 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();
  })
}


最后一次编辑于  2019-05-03
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容