表现:安卓客户端熄屏状态下无法播放下一首声音,报错
已经设置后台阔以播放配置的前提下,
"requiredBackgroundModes": [
"audio"
]
小程序监听播放完成事件,触发下一首播放逻辑,播放逻辑主要是给backgroundAudioManager设置新资源
const backgroundAudioManager = wx.getBackgroundAudioManager()
Page({
data: {
img: "",
title: "",
singer: "",
isPlay: false,
index: 0,
currentSource: {},
list: [
{
id: 589322102,
title: "开篇",
albumId: 3595841,
albumName: 'cppp',
albumTitle: "",
cover: "https://imagev2.xmcdn.com/group54/M03/BE/89/wKgLclw1y2PjEND8AAGN2SKPPNM391.jpg!op_type=3&columns=290&rows=290",
src: "https://aod.cos.tx.xmcdn.com/group62/M03/C8/9F/wKgMZ10CGTOzvH2PAAWkNYbQNNE614.m4a",
},
{
id: 588766344,
title: "第一首",
intro: "",
albumName: 'www',
albumId: 3595841,
albumTitle: "",
cover: "https://imagev2.xmcdn.com/storages/908e-audiofreehighqps/EB/3E/GMCoOR4HTROmAAZkOAHOdIR8.jpeg",
src: "https://aod.cos.tx.xmcdn.com/group62/M07/C8/99/wKgMcV0CGOCTGc4zAAMNLnb_ZI0380.m4a",
}, {
title: "第二首",
intro: "",
albumName: 'whmhhh',
albumId: 3595841,
albumTitle: "",
cover: "https://imagev2.xmcdn.com/storages/8e37-audiofreehighqps/0B/C7/GMCoOSYHSmcmAAwXEwHMq3Jp.jpeg",
src: "https://aod.cos.tx.xmcdn.com/group62/M07/C8/92/wKgMcV0CGMewDkbUAAGoaM7zIss224.m4a",
}
],
},
onLoad: function (options) {
this.getData();
this.init()
},
init() {
backgroundAudioManager.onEnded(() => {
this.nextplay();
})
},
getData: function () {
const {
list,
index
} = this.data
const currentSource = list[index]
this.setData({
currentSource: currentSource
})
this._initAudioManager(currentSource);
},
// 设置资源
_initAudioManager({
src = '',
title = '',
albumName = '',
singer = '',
cover = '',
protocol = 'http',
} = {}) {
backgroundAudioManager.title = ` ${title ? title : albumName}`;
backgroundAudioManager.epname = albumName;
backgroundAudioManager.singer = singer;
backgroundAudioManager.coverImgUrl = cover;
backgroundAudioManager.src = src;
backgroundAudioManager.protocol = protocol;
},
//点击播放
playmp3: function () {
var that = this;
console.log(backgroundAudioManager, 'backgroundAudioManager')
if (this.data.isPlay) {
backgroundAudioManager.play();
} else {
backgroundAudioManager.pause();
}
that.setData({
isPlay: !this.data.isPlay
})
},
nextplay: function () {
wx.showToast({
title: '即将播放下一首',
icon: "none",
duration: 1000,
})
let {
list, index
} = this.data
const currentSource = list[index + 1]
this.setData({
index: index + 1,
currentSource: currentSource
})
this._initAudioManager(currentSource);
},
})
现在遇到安卓客户端在熄屏状态下无法自动进行下一首的播放,开发工具查看,会报错
setBackgroundAudioState:fail: jsapi has no permission, event=setBackgroundAudioState, runningState=background, permissionMsg=permission ok, detail=jsapi permission required playing audio but current not playing audio in background state
其他家像懒人听书/蜻蜓在熄屏状态下表现也是一样的,无法播放下一首,上周四之前还是好的
问题已确定,后续修复
同问