From 8255e39047d0200d4f4aa0c5be26682f8e0fb1d0 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Wed, 4 Nov 2026 09:36:04 +0100 Subject: [PATCH] fix: show a new track started at the index that was playing The player reported a track only when the queue index changed, to drop the repeat stream-start messages playbin posts for one track. Starting another album at the same index (track 1 after track 1) therefore sent no event: the app kept the old track on screen, and pause said nothing was playing, because it had cleared the current track while waiting for that event. A stream-start that begins a track the player was asked to start is now always reported. Only repeats within one track are dropped, and the app treats every report as a new play, so replaying the current track resets its position and scrobbles again. --- CHANGELOG.md | 7 +++ Cargo.lock | 2 +- Cargo.toml | 2 +- .../me.anshorei.Fettleshed.Remus.metainfo.xml | 1 + src/app.rs | 5 +- src/player.rs | 60 +++++++++++++++---- 6 files changed, 61 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56742b4..8b70200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ One section per version, newest first. +## v0.2.1 (2026-11-04) + +### Bug fixes + +- Starting a track from another album at the same position as the one playing, such as track 1 after track 1, now shows the new track and its cover. Pause works straight away instead of saying nothing is playing. +- Replaying the track that is playing counts as a new play: its position resets and the server is told it is playing. + ## v0.2.0 (2026-11-04) ### Features diff --git a/Cargo.lock b/Cargo.lock index 1b4082e..02fb33e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "remus" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "directories", diff --git a/Cargo.toml b/Cargo.toml index fd9df12..119028b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remus" -version = "0.2.0" +version = "0.2.1" edition = "2024" license = "MIT" diff --git a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml index 04aae9e..c9bcffb 100644 --- a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml +++ b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml @@ -20,6 +20,7 @@ + diff --git a/src/app.rs b/src/app.rs index cd621a0..305025c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1519,10 +1519,9 @@ impl App { self.ui.set_np_paused(p); } PlayerEvent::Track(t) => { + // Reported once per track started, so the same index again is a + // new play: another queue started there, or the track replayed. let t = t.filter(|&i| i < self.queue.len()); - if t == self.current { - return; - } self.current = t; self.position = 0.0; self.scrobbled = false; diff --git a/src/player.rs b/src/player.rs index 4e967c1..9f2b7b7 100644 --- a/src/player.rs +++ b/src/player.rs @@ -182,10 +182,12 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex, stop: &AtomicBool, em let Some(bus) = playbin.bus() else { return }; let mut last_tick = Instant::now(); let mut duration = 0.0; - // playbin can post stream-start more than once for one track. + // playbin can post stream-start more than once for one track, so a repeat + // of the last report is dropped. A track that was just started is always + // reported, even at the same index: a new queue, or the same track again. let mut last_track: Option> = None; - let mut report_track = |t: Option| { - if last_track != Some(t) { + let mut report_track = |t: Option, started: bool| { + if started || last_track != Some(t) { last_track = Some(t); emit(PlayerEvent::Track(t)); emit(PlayerEvent::Position(0.0)); @@ -196,15 +198,19 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex, stop: &AtomicBool, em use gst::MessageView; match msg.view() { MessageView::StreamStart(_) => { - let current = { + let (current, started) = { let mut q = lock(queue); - if let Some(p) = q.pending.take() { - q.current = Some(p); - } - q.current + let started = match q.pending.take() { + Some(p) => { + q.current = Some(p); + true + } + None => false, + }; + (q.current, started) }; duration = 0.0; - report_track(current); + report_track(current, started); } MessageView::StateChanged(s) if s.src() == Some(playbin.upcast_ref()) => match s.current() { gst::State::Playing => emit(PlayerEvent::Paused(false)), @@ -218,7 +224,7 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex, stop: &AtomicBool, em q.pending = None; } let _ = playbin.set_state(gst::State::Ready); - report_track(None); + report_track(None, false); } MessageView::Error(err) => { let detail = err.debug().map(|d| d.to_string()).unwrap_or_default(); @@ -239,7 +245,7 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex, stop: &AtomicBool, em start(playbin, &url); } else { let _ = playbin.set_state(gst::State::Ready); - report_track(None); + report_track(None, false); } } _ => {} @@ -357,4 +363,36 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); assert_eq!(tracks, vec![Some(0), Some(1), None]); } + + #[test] + fn starting_at_the_playing_index_reports_the_track_again() { + // SAFETY: set before any thread reads the environment in this test. + unsafe { std::env::set_var("REMUS_AUDIO_SINK", "fakesink") }; + let dir = std::env::temp_dir().join(format!("remus-player-restart-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + // Long enough that nothing finishes while the test runs. + let album_a = vec![silent_wav(&dir, "a1.wav", 10.0), silent_wav(&dir, "a2.wav", 10.0)]; + let album_b = vec![silent_wav(&dir, "b1.wav", 10.0), silent_wav(&dir, "b2.wav", 10.0)]; + + let (tx, rx) = mpsc::channel(); + let player = Player::spawn(move |ev| { + if let PlayerEvent::Track(t) = ev { + let _ = tx.send(t); + } + }) + .unwrap(); + let next = || rx.recv_timeout(Duration::from_secs(3)).ok(); + + player.play_list(&album_a, 0); + assert_eq!(next(), Some(Some(0)), "first album started"); + // Another album, started at the same index as the track playing. + player.play_list(&album_b, 0); + assert_eq!(next(), Some(Some(0)), "second album started at the same index"); + // The playing track started again from the queue. + player.play_index(0); + assert_eq!(next(), Some(Some(0)), "the same track restarted"); + + drop(player); + let _ = std::fs::remove_dir_all(&dir); + } }