添加歌曲预加载功能
This commit is contained in:
@@ -14,6 +14,7 @@ import { apis } from '@renderer/utils/musicSdk/api-source'
|
||||
|
||||
|
||||
const getOtherSourcePromises = new Map()
|
||||
const otherSourceCache = new Map<LX.Music.MusicInfo | LX.Download.ListItem, LX.Music.MusicInfoOnline[]>()
|
||||
export const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
|
||||
|
||||
export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false): Promise<LX.Music.MusicInfoOnline[]> => {
|
||||
@@ -21,6 +22,7 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.
|
||||
// const cachedInfo = await getOtherSourceFromStore(musicInfo.id)
|
||||
// if (cachedInfo.length) return cachedInfo
|
||||
// }
|
||||
if (otherSourceCache.has(musicInfo)) return otherSourceCache.get(musicInfo)!
|
||||
let key: string
|
||||
let searchMusicInfo: {
|
||||
name: string
|
||||
@@ -56,7 +58,10 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.
|
||||
reject(new Error('find music timeout'))
|
||||
}, 15_000)
|
||||
musicSdk.findMusic(searchMusicInfo).then((otherSource) => {
|
||||
resolve(otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[])
|
||||
if (otherSourceCache.size > 100) otherSourceCache.clear()
|
||||
const source = otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[]
|
||||
otherSourceCache.set(musicInfo, source)
|
||||
resolve(source)
|
||||
}).catch(reject).finally(() => {
|
||||
if (timeout) clearTimeout(timeout)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user