Fix web links getting stuck on "loading"; 2.0.3

- Move the player out of "loading" once a yt-dlp link is resolved (mpv
  does not report leaving idle when another track was loaded)
- Pause the previous track while a link is being opened
- Show "Opening link with yt-dlp…" in the hero while resolving
- Fall back to yt-dlp for unknown sites mpv cannot open

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-28 20:08:41 -05:00
commit 37e89e73e6
3 changed files with 28 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "mulberry"
version = "2.0.2"
version = "2.0.3"
edition = "2021"
description = "A Material You music player for Linux"
license = "MIT"

View file

@ -357,6 +357,7 @@ pub struct Player {
xf_t0: Option<(Instant, f64)>,
xf_tried: Option<u64>,
resolve_token: u64,
ytdlp_tried: Option<String>,
last_poll: Instant,
next_engine_id: u8,
}
@ -399,6 +400,7 @@ impl Player {
xf_t0: None,
xf_tried: None,
resolve_token: 0,
ytdlp_tried: None,
last_poll: Instant::now(),
next_engine_id: 1,
};
@ -455,8 +457,14 @@ impl Player {
self.listen = 0.0;
self.start_ts = now_ts();
self.resolve_token = 0;
self.ytdlp_tried = None;
if song.is_stream() && crate::online::needs_resolve(&song.url) && (song.resolved.is_empty() || crate::library::now_secs() as f64 - song.resolved_at > 3600.0) {
self.resolve_token = crate::online::next_token();
// the previous track must not keep playing (or end and advance the playlist) while the link opens
if let Some(m) = &self.main {
m.pause();
}
self.clock.set_playing(false);
self.state = "loading".into();
self.notes.push(Note::SongChanged);
self.notes.push(Note::StateChanged("loading".into()));
@ -508,6 +516,8 @@ impl Player {
}
}
self.load_current(mgr, &song, start, paused);
// mpv only reports leaving idle when it was idle before; the state has to move on here
self.set_state(mgr, if paused { "paused" } else { "playing" });
}
fn engine_for_next(&self, nxt: &Song) -> bool {
@ -725,6 +735,17 @@ impl Player {
}
}
EngineEvent::Error => {
// a page link on a site we don't know: mpv can't open it, so let yt-dlp try once
let try_ytdlp = self.song.as_ref().filter(|s| s.is_stream() && s.resolved.is_empty() && !crate::online::needs_resolve(&s.url) && self.ytdlp_tried.as_deref() != Some(s.url.as_str())).cloned();
if let Some(song) = try_ytdlp {
self.ytdlp_tried = Some(song.url.clone());
self.resolve_token = crate::online::next_token();
self.state = "loading".into();
self.notes.push(Note::StateChanged("loading".into()));
self.notes.push(Note::Message("Opening link…".into()));
self.notes.push(Note::NeedResolve(song));
return;
}
if self.main.as_ref().map(|m| m.is_idle()).unwrap_or(true) && self.state != "stopped" {
self.errors += 1;
self.notes.push(Note::Message("Playback error (unsupported or unreadable media)".into()));

View file

@ -558,8 +558,11 @@ pub fn draw(app: &mut App, ui: &mut Ui, focus: bool) {
}
// ---- info column
let (title, artist, album, meta) = (app.hero.title.clone(), app.hero.artist.clone(), app.hero.album.clone(), app.hero.meta.clone());
let is_loading = app.player.state == "loading";
let (title, artist, album, mut meta) = (app.hero.title.clone(), app.hero.artist.clone(), app.hero.album.clone(), app.hero.meta.clone());
if is_loading {
meta = "Opening link with yt-dlp… this can take up to half a minute".into();
}
let ps = if full { (28.0, 17.0, 17.0) } else { (18.0, 14.0, 13.0) };
let btn_row_h = 56.0;
let wave_h = 28.0;
@ -681,7 +684,8 @@ fn progress_row(app: &mut App, ui: &mut Ui, row: Rect, frac: f32, playing: bool,
let p = ui.painter();
p.text(Pos2::new(row.left(), row.center().y), Align2::LEFT_CENTER, fmt_time(shown_pos), disp(13.0), tcol);
let live = app.player.song.as_ref().map(|s| s.is_stream() && s.length == 0.0).unwrap_or(false);
p.text(Pos2::new(row.right(), row.center().y), Align2::RIGHT_CENTER, if live { "LIVE".to_string() } else { fmt_time(dur) }, disp(13.0), tcol);
let end = if app.player.state == "loading" { "…".to_string() } else if live { "LIVE".to_string() } else { fmt_time(dur) };
p.text(Pos2::new(row.right(), row.center().y), Align2::RIGHT_CENTER, end, disp(13.0), tcol);
if let Some(f) = out.seek {
acts.push(Act::Seek(f as f64));
}