wuyanan

fix |> 修复点击播放早晚报音频时,播控中心显示有延迟问题

... ... @@ -46,6 +46,7 @@ export class AudioSuspensionModel {
// BackgroundAudioController.sharedController().startContinuousTask()
BackgroundAudioController.sharedController().listenPlayEvents()
await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "")
BackgroundAudioController.sharedController().activateSession()
BackgroundAudioController.sharedController().stopUseFeatures()
if (this.playerController.get().getUrl() === url) {
... ...
... ... @@ -53,13 +53,18 @@ export class BackgroundAudioController {
}
// 激活接口要在元数据、控制命令注册完成之后再执行
await this.lastSession?.activate();
// await this.lastSession?.activate();
Logger.debug(TAG, `session create done : sessionId : ${this.lastSession?.sessionId}`);
this.lastProgress = 0
this.hasSetupProgress = false
}
async activateSession() {
await this.lastSession?.activate();
Logger.debug(TAG, `session activate done : sessionId : ${this.lastSession?.sessionId}`);
}
destorySession() {
if (this.lastSession) {
this.lastSession.deactivate();
... ... @@ -74,6 +79,21 @@ export class BackgroundAudioController {
this.lastItemTitle = title || ""
this.lastItemMediaImage = mediaImage
this.lastItemArtist = artist || ""
let metadata: AVSessionManager.AVMetadata = {
assetId: assetId.length > 0 ? assetId : "fake-asset-id",
title: title.length > 0 ? title : " ",
mediaImage: "https://cdnjdphoto.aikan.pdnews.cn/WapApi/800/launcher_icon.png" ,//pixelMapImage ?? ("file://" + mediaImage.id),
artist: artist.length > 0 ? artist : "人日日报"
// duration: duration
};
try {
await this.lastSession?.setAVMetadata(metadata)
Logger.debug(TAG, `SetAVMetadata successfully`);
} catch (err) {
Logger.error(TAG, `Failed to set AVMetadata. Code: ${err.code}, message: ${err.message}`);
} finally {}
}
async setSessionMetaDataWithDuration(assetId: string, title: string, mediaImage: Resource, artist: string, duration: number) {
... ...