From 9237dbbc1842e28552c45bb191318a0ef8ff0f4d Mon Sep 17 00:00:00 2001 From: lyswhut Date: Mon, 28 Oct 2024 23:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=AD=E6=94=BE=E6=9C=AC=E5=9C=B0=E6=AD=8C?= =?UTF-8?q?=E6=9B=B2=E6=97=B6=EF=BC=8C=E5=B0=86=E4=BC=98=E5=85=88=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E8=AF=BB=E5=8F=96=E6=9C=AC=E5=9C=B0=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E7=9A=84=20`jpg`=20=E6=88=96=20`png`=20=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=BD=9C=E4=B8=BA=E6=92=AD=E6=94=BE=E5=B0=81=E9=9D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/utils/music.ts | 7 +++++++ src/renderer/worker/main/music.ts | 1 + 3 files changed, 9 insertions(+) diff --git a/publish/changeLog.md b/publish/changeLog.md index 12da4150..0f16df4a 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -9,6 +9,7 @@ - 修正搜索歌曲提示框文案(#2050) - 优化播放详情页UI,歌曲名字、歌手等文字过长时被截断的问题(#2049) - Scheme URL 的播放歌曲允许更长的专辑名称 +- 播放本地歌曲时,将优先尝试读取本地同名字的 `jpg` 或 `png` 图片作为播放封面显示,若文件不存在则从音频文件内读取,最后再尝试使用在线图片(#2096) ### 修复 diff --git a/src/renderer/utils/music.ts b/src/renderer/utils/music.ts index 65cb8c53..3c935849 100644 --- a/src/renderer/utils/music.ts +++ b/src/renderer/utils/music.ts @@ -117,6 +117,13 @@ const getFileMetadata = async(path: string) => { * @param path 路径 */ export const getLocalMusicFilePic = async(path: string) => { + const filePath = new RegExp('\\' + extname(path) + '$') + let picPath = path.replace(filePath, '.jpg') + let stats = await getFileStats(picPath) + if (stats) return picPath + picPath = path.replace(filePath, '.png') + stats = await getFileStats(picPath) + if (stats) return picPath const metadata = await getFileMetadata(path) if (!metadata) return null const { selectCover } = await import('music-metadata') diff --git a/src/renderer/worker/main/music.ts b/src/renderer/worker/main/music.ts index d2ebc5c8..daeb04c2 100644 --- a/src/renderer/worker/main/music.ts +++ b/src/renderer/worker/main/music.ts @@ -15,6 +15,7 @@ const getTempDir = async() => { export const getMusicFilePic = async(filePath: string) => { const picture = await getLocalMusicFilePic(filePath) if (!picture) return '' + if (typeof picture == 'string') return picture if (picture.data.length > 400_000) { try { const tempDir = await getTempDir()