This commit is contained in:
lyswhut
2022-10-29 11:36:35 +08:00
parent 66b965d9f7
commit e45cee6596
715 changed files with 57096 additions and 31771 deletions
+251
View File
@@ -0,0 +1,251 @@
// import { reactive, ref, shallowRef } from '@common/utils/vueTools'
import {
PlayerMusicInfo,
musicInfo,
isPlay,
status,
statusText,
isShowPlayerDetail,
isShowPlayComment,
isShowLrcSelectContent,
playInfo,
playMusicInfo,
playedList,
tempPlayList,
} from './state'
import { getListMusicsFromCache } from '@renderer/store/list/action'
import { downloadList } from '@renderer/store/download/state'
import { setProgress } from './playProgress'
import { playNext } from '@renderer/core/player'
import { LIST_IDS } from '@common/constants'
import { toRaw } from '@common/utils/vueTools'
type PlayerMusicInfoKeys = keyof typeof musicInfo
const musicInfoKeys: PlayerMusicInfoKeys[] = Object.keys(musicInfo) as PlayerMusicInfoKeys[]
export const setMusicInfo = (_musicInfo: Partial<PlayerMusicInfo>) => {
for (const key of musicInfoKeys) {
const val = _musicInfo[key]
if (val !== undefined) {
// @ts-expect-error
musicInfo[key] = val
}
}
}
export const setPlay = (val: boolean) => {
isPlay.value = val
}
export const setStatus = (val: string) => {
console.log('setStatus', val)
status.value = val
}
export const setStatusText = (val: string) => {
statusText.value = val
}
export const setAllStatus = (val: string) => {
console.log('setAllStatus', val)
status.value = val
statusText.value = val
}
export const setShowPlayerDetail = (val: boolean) => {
isShowPlayerDetail.value = val
}
export const setShowPlayComment = (val: boolean) => {
isShowPlayComment.value = val
}
export const setShowPlayLrcSelectContentLrc = (val: boolean) => {
isShowLrcSelectContent.value = val
}
export const setPlayListId = (listId: string | null) => {
playInfo.playerListId = listId
}
export const getList = (listId: string | null): LX.Music.MusicInfo[] | LX.Download.ListItem[] => {
return listId == LIST_IDS.DOWNLOAD ? downloadList : getListMusicsFromCache(listId)
}
/**
* 更新播放位置
* @returns 播放位置
*/
export const updatePlayIndex = () => {
const indexInfo = getPlayIndex(playMusicInfo.listId, playMusicInfo.musicInfo, playMusicInfo.isTempPlay)
// console.log(indexInfo)
playInfo.playIndex = indexInfo.playIndex
playInfo.playerPlayIndex = indexInfo.playerPlayIndex
return indexInfo
}
export const getPlayIndex = (listId: string | null, musicInfo: LX.Download.ListItem | LX.Music.MusicInfo | null, isTempPlay: boolean): {
playIndex: number
playerPlayIndex: number
} => {
const playerList = getList(playInfo.playerListId)
// if (listIndex < 0) throw new Error('music info not found')
// playInfo.playIndex = listIndex
let playIndex = -1
let playerPlayIndex = -1
if (playerList.length) {
playerPlayIndex = Math.min(playInfo.playerPlayIndex, playerList.length - 1)
}
const list = getList(listId)
if (list.length && musicInfo) {
const currentId = musicInfo.id
playIndex = list.findIndex(m => m.id == currentId)
if (!isTempPlay) {
if (playIndex < 0) {
playerPlayIndex = playerPlayIndex < 1 ? (list.length - 1) : (playerPlayIndex - 1)
} else {
playerPlayIndex = playIndex
}
}
}
return {
playIndex,
playerPlayIndex,
}
}
export const resetPlayerMusicInfo = () => {
setMusicInfo({
id: null,
pic: null,
lrc: null,
tlrc: null,
rlrc: null,
lxlrc: null,
rawlrc: null,
name: '',
singer: '',
album: '',
})
}
const setPlayerMusicInfo = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem | null) => {
if (musicInfo) {
setMusicInfo('progress' in musicInfo ? {
id: musicInfo.id,
pic: musicInfo.metadata.musicInfo.meta.picUrl,
name: musicInfo.metadata.musicInfo.name,
singer: musicInfo.metadata.musicInfo.singer,
album: musicInfo.metadata.musicInfo.meta.albumName,
lrc: null,
tlrc: null,
rlrc: null,
lxlrc: null,
rawlrc: null,
} : {
id: musicInfo.id,
pic: musicInfo.meta.picUrl,
name: musicInfo.name,
singer: musicInfo.singer,
album: musicInfo.meta.albumName,
lrc: null,
tlrc: null,
rlrc: null,
lxlrc: null,
rawlrc: null,
})
} else resetPlayerMusicInfo()
}
/**
* 设置当前播放歌曲的信息
* @param listId 歌曲所属的列表id
* @param musicInfo 歌曲信息
* @param isTempPlay 是否临时播放
*/
export const setPlayMusicInfo = (listId: string | null, musicInfo: LX.Download.ListItem | LX.Music.MusicInfo | null, isTempPlay: boolean = false) => {
musicInfo = toRaw(musicInfo)
playMusicInfo.listId = listId
playMusicInfo.musicInfo = musicInfo
playMusicInfo.isTempPlay = isTempPlay
setPlayerMusicInfo(musicInfo)
setProgress(0, 0)
if (musicInfo == null) {
playInfo.playIndex = -1
playInfo.playerListId = null
playInfo.playerPlayIndex = -1
} else {
const { playIndex, playerPlayIndex } = getPlayIndex(listId, musicInfo, isTempPlay)
playInfo.playIndex = playIndex
playInfo.playerPlayIndex = playerPlayIndex
window.app_event.musicToggled()
}
}
/**
* 将歌曲添加到已播放列表
* @param playMusicInfo playMusicInfo对象
*/
export const addPlayedList = (playMusicInfo: LX.Player.PlayMusicInfo) => {
if (playedList.some(m => m.musicInfo === playMusicInfo.musicInfo)) return
playedList.push(playMusicInfo)
}
/**
* 将歌曲从已播放列表移除
* @param index 歌曲位置
*/
export const removePlayedList = (index: number) => {
playedList.splice(index, 1)
}
/**
* 清空已播放列表
*/
export const clearPlayedList = () => {
playedList.splice(0, playedList.length)
}
/**
* 添加歌曲到稍后播放列表
* @param list 歌曲列表
*/
export const addTempPlayList = (list: LX.Player.TempPlayListItem[]) => {
const topList: Array<{ listId: string, musicInfo: LX.Music.MusicInfo | LX.Download.ListItem }> = []
const bottomList = list.filter(({ isTop, ...musicInfo }) => {
if (isTop) {
topList.push(musicInfo)
return false
}
return true
})
if (topList.length) tempPlayList.unshift(...topList.map(({ musicInfo, listId }) => ({ musicInfo, listId, isTempPlay: true })))
if (bottomList.length) tempPlayList.push(...bottomList.map(({ musicInfo, listId }) => ({ musicInfo, listId, isTempPlay: true })))
if (!playMusicInfo.musicInfo) void playNext()
}
/**
* 从稍后播放列表移除歌曲
* @param index 歌曲位置
*/
export const removeTempPlayList = (index: number) => {
tempPlayList.splice(index, 1)
}
/**
* 清空稍后播放列表
*/
export const clearTempPlayeList = () => {
tempPlayList.splice(0, tempPlayList.length)
}
+37
View File
@@ -0,0 +1,37 @@
import { reactive } from '@common/utils/vueTools'
interface Line {
text: string
time: number
extendedLyrics: string[]
dom_line: HTMLDivElement
}
export const lyric = reactive<{
lines: Line[]
text: string
line: number
offset: number // 歌词延迟
tempOffset: number // 歌词临时延迟
}>({
lines: [],
text: '',
line: 0,
offset: 0, // 歌词延迟
tempOffset: 0, // 歌词临时延迟
})
export const setLines = (lines: Line[]) => {
if (!lines.length && !lyric.lines.length) return
lyric.lines = lines
}
export const setText = (text: string, line: number) => {
lyric.text = text
lyric.line = line
}
export const setOffset = (offset: number) => {
lyric.offset = offset
}
export const setTempOffset = (offset: number) => {
lyric.tempOffset = offset
}
+27
View File
@@ -0,0 +1,27 @@
import { reactive } from '@common/utils/vueTools'
import { formatPlayTime2 } from '@common/utils/common'
export const playProgress = reactive({
nowPlayTime: 0,
maxPlayTime: 0,
progress: 0,
nowPlayTimeStr: '00:00',
maxPlayTimeStr: '00:00',
})
export const setNowPlayTime = (time: number) => {
playProgress.nowPlayTime = time
playProgress.nowPlayTimeStr = formatPlayTime2(time)
playProgress.progress = playProgress.maxPlayTime ? time / playProgress.maxPlayTime : 0
}
export const setMaxplayTime = (time: number) => {
playProgress.maxPlayTime = time
playProgress.maxPlayTimeStr = formatPlayTime2(time)
playProgress.progress = time ? playProgress.nowPlayTime / time : 0
}
export const setProgress = (currentTime: number, totalTime: number) => {
setMaxplayTime(totalTime)
setNowPlayTime(currentTime)
}
+73
View File
@@ -0,0 +1,73 @@
import { reactive, shallowReactive, ref } from '@common/utils/vueTools'
export interface PlayerMusicInfo {
id: string | null
pic: string | null
lrc: string | null
tlrc: string | null
rlrc: string | null
lxlrc: string | null
rawlrc: string | null
// url: string | null
name: string
singer: string
album: string
}
export const musicInfo = window.lxData.musicInfo = reactive<PlayerMusicInfo>({
id: null,
pic: null,
lrc: null,
tlrc: null,
rlrc: null,
lxlrc: null,
rawlrc: null,
// url: null,
name: '',
singer: '',
album: '',
})
export const isPlay = ref(false)
export const status = window.lxData.status = ref('')
export const statusText = ref('')
export const isShowPlayerDetail = ref(false)
export const isShowPlayComment = ref(false)
export const isShowLrcSelectContent = ref(false)
export const playMusicInfo = shallowReactive<{
/**
* 当前播放歌曲的列表 id
*/
musicInfo: LX.Player.PlayMusicInfo['musicInfo'] | null
/**
* 当前播放歌曲的列表 id
*/
listId: LX.Player.PlayMusicInfo['listId'] | null
/**
* 是否属于 “稍后播放”
*/
isTempPlay: boolean
}>({
listId: null,
musicInfo: null,
isTempPlay: false,
})
export const playInfo = shallowReactive<LX.Player.PlayInfo>({
playIndex: -1,
playerListId: null,
playerPlayIndex: -1,
})
export const playedList = window.lxData.playedList = shallowReactive<LX.Player.PlayMusicInfo[]>([])
export const tempPlayList = shallowReactive<LX.Player.PlayMusicInfo[]>([])
window.lxData.playInfo = playInfo
window.lxData.playMusicInfo = playMusicInfo
+13
View File
@@ -0,0 +1,13 @@
import { ref } from '@common/utils/vueTools'
export const volume = ref(0)
export const isMute = ref(false)
export const setVolume = (num: number) => {
volume.value = num
}
export const setMute = (flag: boolean) => {
isMute.value = flag
}