Skip to content

Commit

Permalink
🐛 fix: use metadata's duration for local file
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <sinangentoo@gmail.com>
  • Loading branch information
SimonShiki committed Aug 12, 2024
1 parent 396dcc9 commit 975b60c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src-tauri/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/storages/ncm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ function setupEventListeners () {
let prevSongId: string | number = -1;
sharedStore.sub(currentSongJotai, () => {
const currentSong = sharedStore.get(currentSongJotai);
const replayCurrentSong = sharedStore.get(replayCurrentSongAtom);

if (!currentSong) return;

if (prevSongId !== currentSong.id || replayCurrentSong) {
playCurrentSong();
prevSongId = currentSong.id;
if (replayCurrentSong) {
sharedStore.set(replayCurrentSongAtom, false);
replayCurrentSong = false;
}
}
});
Expand Down Expand Up @@ -217,7 +216,7 @@ function factorToVolume (amplitude: number) {

}

const replayCurrentSongAtom = atom(false);
let replayCurrentSong = false;

async function updateProgress () {
try {
Expand All @@ -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);
Expand Down Expand Up @@ -270,7 +270,7 @@ export function shuffleNewSongs (playlist: Song<string>[], newSongsCount: number
export function setCurrentSong (song: Song<string>) {
const currentSong = sharedStore.get(currentSongJotai);
if (currentSong && currentSong.id === song.id) {
sharedStore.set(replayCurrentSongAtom, true);
replayCurrentSong = true;
}
sharedStore.set(currentSongJotai, song);
}
Expand Down

0 comments on commit 975b60c

Please sign in to comment.