播放本地歌曲时,将优先尝试读取本地同名字的 jpg 或 png 图片作为播放封面显示

This commit is contained in:
lyswhut
2024-10-28 23:04:48 +08:00
parent 68ac1b7641
commit 9237dbbc18
3 changed files with 9 additions and 0 deletions
+7
View File
@@ -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')
+1
View File
@@ -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()