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.
This commit is contained in:
@@ -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
|
||||
|
||||
Generated
+1
-1
@@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "remus"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"directories",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "remus"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
</supports>
|
||||
<content_rating type="oars-1.1"/>
|
||||
<releases>
|
||||
<release version="0.2.1" date="2026-11-04"/>
|
||||
<release version="0.2.0" date="2026-11-04"/>
|
||||
<release version="0.1.0" date="2026-11-04"/>
|
||||
</releases>
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
+49
-11
@@ -182,10 +182,12 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex<Queue>, 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<Option<usize>> = None;
|
||||
let mut report_track = |t: Option<usize>| {
|
||||
if last_track != Some(t) {
|
||||
let mut report_track = |t: Option<usize>, 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<Queue>, 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<Queue>, 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<Queue>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user