新增 我的列表-换源播放 功能
This commit is contained in:
@@ -8,17 +8,18 @@ import {
|
||||
} from './online'
|
||||
import { buildLyricInfo, getCachedLyricInfo } from './utils'
|
||||
|
||||
export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
||||
export const getMusicUrl = async({ musicInfo, isRefresh, allowToggleSource = true, onToggleSource = () => {} }: {
|
||||
musicInfo: LX.Download.ListItem
|
||||
isRefresh: boolean
|
||||
onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void
|
||||
allowToggleSource?: boolean
|
||||
}): Promise<string> => {
|
||||
if (!isRefresh) {
|
||||
const path = await getDownloadFilePath(musicInfo, appSetting['download.savePath'])
|
||||
if (path) return path
|
||||
}
|
||||
|
||||
return getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource })
|
||||
return getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource, allowToggleSource })
|
||||
}
|
||||
|
||||
export const getPicUrl = async({ musicInfo, isRefresh, listId, onToggleSource = () => {} }: {
|
||||
|
||||
@@ -24,18 +24,20 @@ export const getMusicUrl = async({
|
||||
quality,
|
||||
isRefresh = false,
|
||||
onToggleSource,
|
||||
allowToggleSource,
|
||||
}: {
|
||||
musicInfo: LX.Music.MusicInfo | LX.Download.ListItem
|
||||
isRefresh?: boolean
|
||||
quality?: LX.Quality
|
||||
onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void
|
||||
allowToggleSource?: boolean
|
||||
}): Promise<string> => {
|
||||
if ('progress' in musicInfo) {
|
||||
return getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource })
|
||||
return getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource, allowToggleSource })
|
||||
} else if (musicInfo.source == 'local') {
|
||||
return getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource })
|
||||
return getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource, allowToggleSource })
|
||||
} else {
|
||||
return getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource })
|
||||
return getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource, allowToggleSource })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,10 @@ const getOtherSourceByLocal = async<T>(musicInfo: LX.Music.MusicInfoLocal, handl
|
||||
throw new Error('source not found')
|
||||
}
|
||||
|
||||
export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
||||
export const getMusicUrl = async({ musicInfo, isRefresh, allowToggleSource = true, onToggleSource = () => {} }: {
|
||||
musicInfo: LX.Music.MusicInfoLocal
|
||||
isRefresh: boolean
|
||||
allowToggleSource?: boolean
|
||||
onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void
|
||||
}): Promise<string> => {
|
||||
if (!isRefresh) {
|
||||
@@ -83,6 +84,8 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
})
|
||||
} catch {}
|
||||
|
||||
if (!allowToggleSource) throw new Error('failed')
|
||||
|
||||
onToggleSource()
|
||||
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||
return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
|
||||
@@ -23,6 +23,10 @@ import { addDislikeInfo } from '@renderer/core/dislikeList'
|
||||
// import { checkMusicFileAvailable } from '@renderer/utils/music'
|
||||
|
||||
let gettingUrlId = ''
|
||||
const createGettingUrlId = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem) => {
|
||||
const tInfo = 'progress' in musicInfo ? musicInfo.metadata.musicInfo.meta.toggleMusicInfo : musicInfo.meta.toggleMusicInfo
|
||||
return `${musicInfo.id}_${tInfo?.id ?? ''}`
|
||||
}
|
||||
const createDelayNextTimeout = (delay: number) => {
|
||||
let timeout: NodeJS.Timeout | null
|
||||
const clearDelayNextTimeout = () => {
|
||||
@@ -56,7 +60,7 @@ const { addDelayNextTimeout: addLoadTimeout, clearDelayNextTimeout: clearLoadTim
|
||||
*/
|
||||
const diffCurrentMusicInfo = (curMusicInfo: LX.Music.MusicInfo | LX.Download.ListItem): boolean => {
|
||||
// return curMusicInfo !== playMusicInfo.musicInfo || isPlay.value
|
||||
return gettingUrlId != curMusicInfo.id || curMusicInfo.id != playMusicInfo.musicInfo?.id || isPlay.value
|
||||
return gettingUrlId != createGettingUrlId(curMusicInfo) || curMusicInfo.id != playMusicInfo.musicInfo?.id || isPlay.value
|
||||
}
|
||||
|
||||
let cancelDelayRetry: (() => void) | null = null
|
||||
@@ -87,14 +91,21 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt
|
||||
if (appSetting['player.autoSkipOnError']) addLoadTimeout()
|
||||
|
||||
// const type = getPlayType(appSetting['player.highQuality'], musicInfo)
|
||||
let toggleMusicInfo = ('progress' in musicInfo ? musicInfo.metadata.musicInfo : musicInfo).meta.toggleMusicInfo
|
||||
|
||||
return getMusicUrl({
|
||||
musicInfo,
|
||||
return (toggleMusicInfo ? getMusicUrl({
|
||||
musicInfo: toggleMusicInfo,
|
||||
isRefresh,
|
||||
onToggleSource(mInfo) {
|
||||
if (diffCurrentMusicInfo(musicInfo)) return
|
||||
setAllStatus(window.i18n.t('toggle_source_try'))
|
||||
},
|
||||
allowToggleSource: false,
|
||||
}) : Promise.reject(new Error('not found'))).catch(async() => {
|
||||
return getMusicUrl({
|
||||
musicInfo,
|
||||
isRefresh,
|
||||
onToggleSource(mInfo) {
|
||||
if (diffCurrentMusicInfo(musicInfo)) return
|
||||
setAllStatus(window.i18n.t('toggle_source_try'))
|
||||
},
|
||||
})
|
||||
}).then(url => {
|
||||
if (window.lx.isPlayedStop || diffCurrentMusicInfo(musicInfo)) return null
|
||||
|
||||
@@ -118,7 +129,7 @@ export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem
|
||||
// if (appSetting['player.autoSkipOnError']) addLoadTimeout()
|
||||
if (!diffCurrentMusicInfo(musicInfo)) return
|
||||
if (cancelDelayRetry) cancelDelayRetry()
|
||||
gettingUrlId = musicInfo.id
|
||||
gettingUrlId = createGettingUrlId(musicInfo)
|
||||
void getMusicPlayUrl(musicInfo, isRefresh).then((url) => {
|
||||
if (!url) return
|
||||
setResource(url)
|
||||
@@ -458,7 +469,7 @@ export const playPrev = async(isAutoToggle = false): Promise<void> => {
|
||||
export const play = () => {
|
||||
if (playMusicInfo.musicInfo == null) return
|
||||
if (isEmpty()) {
|
||||
if (playMusicInfo.musicInfo.id != gettingUrlId) setMusicUrl(playMusicInfo.musicInfo)
|
||||
if (createGettingUrlId(playMusicInfo.musicInfo) != gettingUrlId) setMusicUrl(playMusicInfo.musicInfo)
|
||||
return
|
||||
}
|
||||
setPlay()
|
||||
|
||||
Reference in New Issue
Block a user