feat: media keys, device recovery, settings and a macOS app bundle
- Media keys and Now Playing (souvlaki): title, artist, album, cover and position published on track and state changes; play/pause/toggle, next/previous and seeking from the OS controls - Audio engine reopens the default output when the device changes or disappears, reloading the current track at the same position; with no device it keeps looking and resumes when one appears. Underruns are ignored rather than treated as device loss - Settings screen: streaming quality (Best, Balanced <=192 kbps, Data saver <=128 kbps), appearance (system/light/dark), clear cover cache; quality, appearance and volume persist as JSON in the config folder - Bitrate cap chooses the best variant within it, or the smallest above - Lyrics failures get a retry button - App icon drawn by tool/make_icon.py; tool/bundle-macos.sh builds an ad-hoc signed Musyx.app (--install copies it to /Applications) - Release profile: thin LTO and stripped symbols
This commit is contained in:
1 parent
e2312f2d40
commit
60156aba94
19 files changed
+1039
-94
No files matched your search
+14
-10
@@ -139,21 +139,23 @@ impl Stream {
|
||||
}
|
||||
}
|
||||
|
||||
/// Picks the variant to play: full tracks over previews, MP3 over AAC (MP3 seeks
|
||||
/// reliably), then the highest bitrate.
|
||||
/// Picks the variant to play: full tracks over previews, then the highest bitrate
|
||||
/// within `max_kbps` (or the lowest there is, when everything is above it), then
|
||||
/// MP3 over AAC (MP3 seeks reliably).
|
||||
pub(crate) fn best_variant(
|
||||
variants: &[yamuse::models::DownloadInfo],
|
||||
max_kbps: Option<u32>,
|
||||
) -> Option<&yamuse::models::DownloadInfo> {
|
||||
let cap = max_kbps.map_or(i64::MAX, i64::from);
|
||||
variants
|
||||
.iter()
|
||||
.filter(|v| v.download_info_url.is_some())
|
||||
.filter(|v| matches!(v.codec.as_deref(), Some("mp3" | "aac")))
|
||||
.max_by_key(|v| {
|
||||
(
|
||||
!v.preview.unwrap_or(false),
|
||||
v.codec.as_deref() == Some("mp3"),
|
||||
v.bitrate_in_kbps.unwrap_or(0),
|
||||
)
|
||||
let kbps = v.bitrate_in_kbps.unwrap_or(0);
|
||||
// Within the cap, higher is better; above it, closer to the cap is better.
|
||||
let fit = if kbps <= cap { (1, kbps) } else { (0, -kbps) };
|
||||
(!v.preview.unwrap_or(false), fit, v.codec.as_deref() == Some("mp3"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -212,12 +214,14 @@ mod tests {
|
||||
{"codec":"flac","bitrateInKbps":900,"downloadInfoUrl":"f"}]"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(best_variant(&v).unwrap().download_info_url.as_deref(), Some("c"));
|
||||
assert_eq!(best_variant(&v, None).unwrap().download_info_url.as_deref(), Some("c"));
|
||||
assert_eq!(best_variant(&v, Some(192)).unwrap().download_info_url.as_deref(), Some("b"));
|
||||
assert_eq!(best_variant(&v, Some(64)).unwrap().download_info_url.as_deref(), Some("b"), "nothing fits: take the smallest");
|
||||
let previews: Vec<yamuse::models::DownloadInfo> = serde_json::from_str(
|
||||
r#"[{"codec":"mp3","bitrateInKbps":128,"downloadInfoUrl":"p","preview":true}]"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(best_variant(&previews).unwrap().preview.unwrap());
|
||||
assert!(best_variant(&[]).is_none());
|
||||
assert!(best_variant(&previews, None).unwrap().preview.unwrap());
|
||||
assert!(best_variant(&[], None).is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user