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

pull/2078/head^2
lyswhut 2024-10-28 23:04:48 +08:00
parent 68ac1b7641
commit 9237dbbc18
3 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@
- 修正搜索歌曲提示框文案(#2050 - 修正搜索歌曲提示框文案(#2050
- 优化播放详情页UI歌曲名字、歌手等文字过长时被截断的问题#2049 - 优化播放详情页UI歌曲名字、歌手等文字过长时被截断的问题#2049
- Scheme URL 的播放歌曲允许更长的专辑名称 - Scheme URL 的播放歌曲允许更长的专辑名称
- 播放本地歌曲时,将优先尝试读取本地同名字的 `jpg``png` 图片作为播放封面显示,若文件不存在则从音频文件内读取,最后再尝试使用在线图片(#2096
### 修复 ### 修复

View File

@ -117,6 +117,13 @@ const getFileMetadata = async(path: string) => {
* @param path * @param path
*/ */
export const getLocalMusicFilePic = async(path: string) => { 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) const metadata = await getFileMetadata(path)
if (!metadata) return null if (!metadata) return null
const { selectCover } = await import('music-metadata') const { selectCover } = await import('music-metadata')

View File

@ -15,6 +15,7 @@ const getTempDir = async() => {
export const getMusicFilePic = async(filePath: string) => { export const getMusicFilePic = async(filePath: string) => {
const picture = await getLocalMusicFilePic(filePath) const picture = await getLocalMusicFilePic(filePath)
if (!picture) return '' if (!picture) return ''
if (typeof picture == 'string') return picture
if (picture.data.length > 400_000) { if (picture.data.length > 400_000) {
try { try {
const tempDir = await getTempDir() const tempDir = await getTempDir()