wuyanan

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

@@ -46,6 +46,7 @@ export class AudioSuspensionModel { @@ -46,6 +46,7 @@ export class AudioSuspensionModel {
46 // BackgroundAudioController.sharedController().startContinuousTask() 46 // BackgroundAudioController.sharedController().startContinuousTask()
47 BackgroundAudioController.sharedController().listenPlayEvents() 47 BackgroundAudioController.sharedController().listenPlayEvents()
48 await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "") 48 await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "")
  49 + BackgroundAudioController.sharedController().activateSession()
49 BackgroundAudioController.sharedController().stopUseFeatures() 50 BackgroundAudioController.sharedController().stopUseFeatures()
50 51
51 if (this.playerController.get().getUrl() === url) { 52 if (this.playerController.get().getUrl() === url) {
@@ -53,13 +53,18 @@ export class BackgroundAudioController { @@ -53,13 +53,18 @@ export class BackgroundAudioController {
53 } 53 }
54 54
55 // 激活接口要在元数据、控制命令注册完成之后再执行 55 // 激活接口要在元数据、控制命令注册完成之后再执行
56 - await this.lastSession?.activate(); 56 + // await this.lastSession?.activate();
57 Logger.debug(TAG, `session create done : sessionId : ${this.lastSession?.sessionId}`); 57 Logger.debug(TAG, `session create done : sessionId : ${this.lastSession?.sessionId}`);
58 58
59 this.lastProgress = 0 59 this.lastProgress = 0
60 this.hasSetupProgress = false 60 this.hasSetupProgress = false
61 } 61 }
62 62
  63 + async activateSession() {
  64 + await this.lastSession?.activate();
  65 + Logger.debug(TAG, `session activate done : sessionId : ${this.lastSession?.sessionId}`);
  66 + }
  67 +
63 destorySession() { 68 destorySession() {
64 if (this.lastSession) { 69 if (this.lastSession) {
65 this.lastSession.deactivate(); 70 this.lastSession.deactivate();
@@ -74,6 +79,21 @@ export class BackgroundAudioController { @@ -74,6 +79,21 @@ export class BackgroundAudioController {
74 this.lastItemTitle = title || "" 79 this.lastItemTitle = title || ""
75 this.lastItemMediaImage = mediaImage 80 this.lastItemMediaImage = mediaImage
76 this.lastItemArtist = artist || "" 81 this.lastItemArtist = artist || ""
  82 +
  83 + let metadata: AVSessionManager.AVMetadata = {
  84 + assetId: assetId.length > 0 ? assetId : "fake-asset-id",
  85 + title: title.length > 0 ? title : " ",
  86 + mediaImage: "https://cdnjdphoto.aikan.pdnews.cn/WapApi/800/launcher_icon.png" ,//pixelMapImage ?? ("file://" + mediaImage.id),
  87 + artist: artist.length > 0 ? artist : "人日日报"
  88 + // duration: duration
  89 + };
  90 +
  91 + try {
  92 + await this.lastSession?.setAVMetadata(metadata)
  93 + Logger.debug(TAG, `SetAVMetadata successfully`);
  94 + } catch (err) {
  95 + Logger.error(TAG, `Failed to set AVMetadata. Code: ${err.code}, message: ${err.message}`);
  96 + } finally {}
77 } 97 }
78 98
79 async setSessionMetaDataWithDuration(assetId: string, title: string, mediaImage: Resource, artist: string, duration: number) { 99 async setSessionMetaDataWithDuration(assetId: string, title: string, mediaImage: Resource, artist: string, duration: number) {