Improved lyric syncing, fetch

- uses a somewhat more sane way to parse lyrics and teardown timeouts
- adds 'seeked' to setCurrentTime to make detecting seeks in lyric much easier
- adds ability to fetch lyrics from genius/netease (desktop only)
This commit is contained in:
Kendall Garner 2023-05-28 14:31:49 -07:00 committed by Jeff
parent 23f9bd4e9f
commit 85d2576bdc
25 changed files with 907 additions and 118 deletions

View file

@ -15,6 +15,7 @@ export interface PlayerState {
nextIndex: number;
player: 1 | 2;
previousIndex: number;
seek: boolean;
shuffledIndex: number;
song?: QueueSong;
status: PlayerStatus;
@ -76,7 +77,7 @@ export interface PlayerSlice extends PlayerState {
reorderQueue: (rowUniqueIds: string[], afterUniqueId?: string) => PlayerData;
restoreQueue: (data: Partial<PlayerState>) => PlayerData;
setCurrentIndex: (index: number) => PlayerData;
setCurrentTime: (time: number) => void;
setCurrentTime: (time: number, seek?: boolean) => void;
setCurrentTrack: (uniqueId: string) => PlayerData;
setFavorite: (ids: string[], favorite: boolean) => string[];
setMuted: (muted: boolean) => void;
@ -668,8 +669,9 @@ export const usePlayerStore = create<PlayerSlice>()(
return get().actions.getPlayerData();
},
setCurrentTime: (time) => {
setCurrentTime: (time, seek = false) => {
set((state) => {
state.current.seek = seek;
state.current.time = time;
});
},
@ -834,6 +836,7 @@ export const usePlayerStore = create<PlayerSlice>()(
nextIndex: 0,
player: 1,
previousIndex: 0,
seek: false,
shuffledIndex: 0,
song: {} as QueueSong,
status: PlayerStatus.PAUSED,
@ -944,6 +947,8 @@ export const useShuffleStatus = () => usePlayerStore((state) => state.shuffle);
export const useCurrentTime = () => usePlayerStore((state) => state.current.time);
export const useSeeked = () => usePlayerStore((state) => state.current.seek);
export const useVolume = () => usePlayerStore((state) => state.volume);
export const useMuted = () => usePlayerStore((state) => state.muted);

View file

@ -19,6 +19,7 @@ import {
PlaybackType,
TableType,
Platform,
LyricSource,
} from '/@/renderer/types';
export type SidebarItemType = {
@ -121,6 +122,11 @@ export interface SettingsState {
bindings: Record<BindingActions, { allowGlobal: boolean; hotkey: string; isGlobal: boolean }>;
globalMediaHotkeys: boolean;
};
lyrics: {
fetch: boolean;
follow: boolean;
sources: LyricSource[];
};
playback: {
audioDeviceId?: string | null;
crossfadeDuration: number;
@ -202,6 +208,11 @@ const initialState: SettingsState = {
},
globalMediaHotkeys: true,
},
lyrics: {
fetch: false,
follow: true,
sources: [],
},
playback: {
audioDeviceId: undefined,
crossfadeDuration: 5,
@ -416,3 +427,5 @@ export const useHotkeySettings = () => useSettingsStore((state) => state.hotkeys
export const useMpvSettings = () =>
useSettingsStore((state) => state.playback.mpvProperties, shallow);
export const useLyricsSettings = () => useSettingsStore((state) => state.lyrics, shallow);