优化本地歌曲内嵌封面过大时的加载方式
parent
05f5cc4fe8
commit
77c2e962ec
|
@ -1,6 +1,6 @@
|
|||
### 新增
|
||||
|
||||
- 新增 是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940)
|
||||
- 新增 设置-播放设置-是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940)
|
||||
- 新增设置-播放详情页设置-延迟歌词滚动设置(#1985)
|
||||
- 新增鼠标在音量按钮使用滚轮时可以调整音量大小的功能(#2000)
|
||||
- 新增设置-下载设置-同时下载任务数设置(#1498)
|
||||
|
@ -10,6 +10,7 @@
|
|||
|
||||
- 优化侧栏图标显示,修复图标可能被裁切的问题(#1960)
|
||||
- 托盘图标添加当前播放歌曲名字显示
|
||||
- 优化本地歌曲内嵌封面过大时的加载方式
|
||||
|
||||
### 修复
|
||||
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
import { getLocalMusicFileLyric, getLocalMusicFilePic } from '@renderer/utils/music'
|
||||
import path from 'node:path'
|
||||
import os from 'node:os'
|
||||
import fs from 'node:fs/promises'
|
||||
import { checkPath } from '@common/utils/nodejs'
|
||||
|
||||
const getTempDir = async() => {
|
||||
const tempDir = path.join(os.tmpdir(), 'lxmusic_temp')
|
||||
if (!await checkPath(tempDir)) {
|
||||
await fs.mkdir(tempDir, { recursive: true })
|
||||
}
|
||||
return tempDir
|
||||
}
|
||||
|
||||
export const getMusicFilePic = async(filePath: string) => {
|
||||
const picture = await getLocalMusicFilePic(filePath)
|
||||
if (!picture) return ''
|
||||
if (picture.data.length > 400_000) {
|
||||
try {
|
||||
const tempDir = await getTempDir()
|
||||
const tempFile = path.join(tempDir, path.basename(filePath) + '.' + picture.format.split('/')[1])
|
||||
await fs.writeFile(tempFile, picture.data)
|
||||
return tempFile
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
return `data:${picture.format};base64,${Buffer.from(picture.data).toString('base64')}`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue