From d2347c37da49fc527b8ddcecbe5fcc9285d30982 Mon Sep 17 00:00:00 2001 From: ccfriend Date: Mon, 17 Feb 2025 21:52:26 +0800 Subject: [PATCH] temp add avsession title as lyric Change-Id: Id645b1d0bdbc782d10f672b005036c3594190bfd Signed-off-by: ccfriend --- entry/src/main/ets/lyric/LrcView.ets | 5 +++++ entry/src/main/ets/utils/MediaService.ets | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/entry/src/main/ets/lyric/LrcView.ets b/entry/src/main/ets/lyric/LrcView.ets index eb36539..7215815 100644 --- a/entry/src/main/ets/lyric/LrcView.ets +++ b/entry/src/main/ets/lyric/LrcView.ets @@ -15,6 +15,7 @@ import { Animator, AnimatorResult } from '@kit.ArkUI'; import { Logger } from '../utils/Logger'; +import { MediaService } from '../utils/MediaService'; import { LrcEntry } from './LrcEntry'; import { angleToRadian } from './LrcUtils'; import { Rectangle, LyricTopPosition, LyricScrollEffect } from './LyricConst'; @@ -533,6 +534,10 @@ export default struct shiLrcView { } else { lineHeight = this.drawSingleLine(lyric, textMetrics, isCurrent); } + // update lyric to avsession + if (isCurrent) { + MediaService.getInstance().updateLyric(lyric.lineWords); + } return lineHeight; } diff --git a/entry/src/main/ets/utils/MediaService.ets b/entry/src/main/ets/utils/MediaService.ets index 4d0c509..60b4693 100644 --- a/entry/src/main/ets/utils/MediaService.ets +++ b/entry/src/main/ets/utils/MediaService.ets @@ -260,6 +260,25 @@ export class MediaService { } } + public async updateLyric(lyric: string): Promise { + try { + Logger.info(TAG, 'updateLyric success' + JSON.stringify(lyric)); + let metadata: avSession.AVMetadata = { + assetId: `${this.musicIndex}`, + title: lyric, + artist: this.songList[this.musicIndex].singer, + duration: this.getDuration(), + }; + this.session?.setAVMetadata(metadata).then(() => { + Logger.info(TAG, 'SetAVMetadata successfully'); + }).catch((error: BusinessError) => { + Logger.error(TAG, `SetAVMetadata BusinessError: code: ${error.code}, message: ${error.message}`); + }); + } catch (error) { + Logger.error(TAG, `SetAVMetadata err, code: ${JSON.stringify(error)}`); + } + } + public controlPlay(musicIndex: number): void { this.isFirstLoadAsset = false; this.playByIndex(musicIndex); -- Gitee