diff --git a/entry/src/main/ets/lyric/LrcView.ets b/entry/src/main/ets/lyric/LrcView.ets index eb3653932205d2d9e9a91d059ec6b633f7633e1f..7215815dacf813c2f9395cc6f6db4ba298898c12 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 4d0c5094b30610ea16c85061754044cf7d7811c8..60b4693cb1d0aea075bf99cc527e868debb306a6 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);