From 975b60c9eb96229542da4272cf4ad8135ba9ade1 Mon Sep 17 00:00:00 2001 From: SimonShiki Date: Mon, 12 Aug 2024 09:44:40 +0800 Subject: [PATCH] :bug: fix: use metadata's duration for local file Signed-off-by: SimonShiki --- src-tauri/src/audio.rs | 3 --- src/storages/ncm.ts | 1 - src/utils/player.ts | 12 ++++++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src-tauri/src/audio.rs b/src-tauri/src/audio.rs index a705574..516962d 100644 --- a/src-tauri/src/audio.rs +++ b/src-tauri/src/audio.rs @@ -271,9 +271,6 @@ pub async fn play_local_file(app: tauri::AppHandle, audio_state: State<'_, Audio let sink = Sink::try_new(&audio_state.stream_handle) .map_err(|e| AppError::SinkCreationError(e.to_string()))?; - // Report the actual duration - let _ = app.emit("update_duration", source.total_duration().unwrap().as_millis()); - sink.append(source); *sink_guard = Some(sink); diff --git a/src/storages/ncm.ts b/src/storages/ncm.ts index 8d9a5d3..f265695 100644 --- a/src/storages/ncm.ts +++ b/src/storages/ncm.ts @@ -335,7 +335,6 @@ export class NCM implements AbstractStorage { } private get config () { - console.log(sharedStore.get(this.ncmStorageConfigJotai)); return (sharedStore.get(this.ncmStorageConfigJotai) ?? defaultConfig) as NCMConfig; } diff --git a/src/utils/player.ts b/src/utils/player.ts index 2d4efcc..c980c90 100644 --- a/src/utils/player.ts +++ b/src/utils/player.ts @@ -156,7 +156,6 @@ function setupEventListeners () { let prevSongId: string | number = -1; sharedStore.sub(currentSongJotai, () => { const currentSong = sharedStore.get(currentSongJotai); - const replayCurrentSong = sharedStore.get(replayCurrentSongAtom); if (!currentSong) return; @@ -164,7 +163,7 @@ function setupEventListeners () { playCurrentSong(); prevSongId = currentSong.id; if (replayCurrentSong) { - sharedStore.set(replayCurrentSongAtom, false); + replayCurrentSong = false; } } }); @@ -217,7 +216,7 @@ function factorToVolume (amplitude: number) { } -const replayCurrentSongAtom = atom(false); +let replayCurrentSong = false; async function updateProgress () { try { @@ -233,11 +232,12 @@ async function checkSongProgress () { const playmode = sharedStore.get(playModeJotai); const progress = sharedStore.get(progressJotai); - if (playing && song && ((song.duration ?? Infinity) / 1000) - progress <= 0.01) { + if (playing && song && ((song.duration ?? Infinity) / 1000) - progress <= 0.1) { sharedStore.set(backendPlayingJotai, false); switch (playmode) { case 'single-recycle': - sharedStore.set(replayCurrentSongAtom, true); + replayCurrentSong = true; + playCurrentSong(); break; case 'single': sharedStore.set(playingJotai, false); @@ -270,7 +270,7 @@ export function shuffleNewSongs (playlist: Song[], newSongsCount: number export function setCurrentSong (song: Song) { const currentSong = sharedStore.get(currentSongJotai); if (currentSong && currentSong.id === song.id) { - sharedStore.set(replayCurrentSongAtom, true); + replayCurrentSong = true; } sharedStore.set(currentSongJotai, song); }