设置代码如下,但是播控中心展示时间异常,看日志状态设置成功了的SetAVPlaybackState successfully。
this.getAvSession(context).then(result => {
// 简单设置一个播放状态 - 暂停 未收藏
let playbackState: AVSessionManager.AVPlaybackState = {
state: state,
position: {
elapsedTime: current, // 已经播放的位置,以ms为单位
updateTime: new Date().getTime(), // 应用更新当前位置的时间戳,以ms为单位
},
duration: total, // 资源的时长,以ms为单位
};
console.info(`SetAVPlaybackState2 successfully_` + state);
this.currentAVSession!!.setAVPlaybackState(playbackState, (err) => {
if (err) {
console.error(`Failed to set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
} else {
console.info(`SetAVPlaybackState successfully_` + state);
}
});
})
需要在设置setAVMetadata传duration,更新状态传无效。