wx.getBackgroundAudioManager()安卓无法播放
发布于 5 年前 作者 yang62 12008 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

用wx.getBackgroundAudioManager()播放音频在iOS和调试工具上都没有问题,但是在安卓机上音频加载失败,也没报错

  • 提供一个最简复现 Demo

const bgMusic = wx.getBackgroundAudioManager();

buttonPlay: function(e){  //src:https://teststatic.yxxy.tv/activity/tidbits/audio/20190128/1548657698_5c4ea422175c7.m4a

var index = e.currentTarget.dataset.index;  //当前播放音频下标

wx.showLoading({

title: ‘音频加载中’,

})

var that = this;

var src = e.currentTarget.dataset.src;

bgMusic.title = ‘音频’

bgMusic.epname = ‘音频’

bgMusic.src = src;

console.log(src, bgMusic)

bgMusic.play();

//音频播放中

bgMusic.onPlay(() => {

wx.hideLoading()

that.setData({

openIndex: index

})

})

bgMusic.onTimeUpdate(() => {

//bgMusic.duration总时长  bgMusic.currentTime当前进度

var offset = bgMusic.currentTime;

var currentTime = parseInt(bgMusic.currentTime);

var min = “0” + parseInt(currentTime / 60);

var max = parseInt(bgMusic.duration);

that.setData({

offset: currentTime,

starttime: that.getTime(currentTime),

max: max,

})

})

//播放结束

bgMusic.onEnded(() => {

that.setData({

starttime: ‘00:00’,

openIndex: 99,

offset: 0

})

console.log(“音乐播放结束”);

})

},

2 回复

正解,安卓不支持ADTS格式

提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

回到顶部