Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Stop a failed audio key from looking like a frozen app

Lelonioc9bbb0cbecc6
diff --git a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
index 59a8a76..662c860 100644
--- a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
+++ b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
@@ -2,27 +2,27 @@ C/C++ Structured Logc
a
_/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �٣��3  ��߈�3`
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ��߈�3`
^
-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json  �٣��3� ��߈�3e
+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json  �����3� ��߈�3e
c
-a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json  �٣��3� ��߈�3R
+a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json  �����3� ��߈�3R
P
-N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja  �٣��3� ��߈�3V
+N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja  �����3� ��߈�3V
T
-R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt  �٣��3[
+R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt  �����3[
Y
-W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt  �٣��3 @ ��߈�3\
+W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt  �����3 @ ��߈�3\
Z
-X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json  �٣��3֚ ��߈�3`
+X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json  �����3֚ ��߈�3`
^
-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin  �٣��3 �" ��߈�3f
+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin  �����3 �" ��߈�3f
d
-b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt  �٣��3
+b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt  �����3
� ��߈�3Y
W
-U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json  �٣��3  ( ��߈�3^
+U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json  �����3  ( ��߈�3^
\
-Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt  �٣��3  Y ��߈�3D
+Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt  �����3  Y ��߈�3D
B
-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �٣��3 � �Ȅ��3
\ No newline at end of file
+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �����3 � �Ȅ��3
\ No newline at end of file
diff --git a/app/icon-src/wave-square.svg b/app/icon-src/wave-square.svg
new file mode 100644
index 0000000..5b1778a
--- /dev/null
+++ b/app/icon-src/wave-square.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M240,128v56a8,8,0,0,1-8,8H128a8,8,0,0,1-8-8V80H32v48a8,8,0,0,1-16,0V72a8,8,0,0,1,8-8H128a8,8,0,0,1,8,8V176h88V128a8,8,0,0,1,16,0Z"></path></svg>
\ No newline at end of file
diff --git a/native/src/engine.rs b/native/src/engine.rs
index 1a38b8f..8350816 100644
--- a/native/src/engine.rs
+++ b/native/src/engine.rs
@@ -184,11 +184,18 @@ pub fn start(
// falls back to the platform default id instead, which no longer matches the
// id the OAuth token was minted for, and every spclient call fails with
// "Login request was denied: BAD_REQUEST".
+ // Bounded, and swept before it is opened.
+ //
+ // It was neither: an audio cache with no limit had grown past a gigabyte on
+ // the test phone, and the half-finished downloads librespot writes next to
+ // it — one temporary file per interrupted load, and skipping interrupts a
+ // lot of loads — were never collected at all.
+ sweep_stale_downloads(cache_dir);
let cache = Cache::new(
Some(std::path::Path::new(credentials_dir)),
None,
Some(std::path::Path::new(cache_dir)),
- None,
+ Some(AUDIO_CACHE_LIMIT),
)
.map_err(|e| format!("cache failed: {e}"))?;
@@ -323,13 +330,33 @@ fn spawn_event_pump(
log::info!("event pump started for device {device_name}");
// What the account's listening history is built from; see events.rs.
let mut history = History::new(session, state_dir);
+ // The track whose successor has already been fetched.
+ let mut preloaded: Option<String> = None;
while let Some(event) = events.blocking_recv() {
history.observe(&event);
- // As soon as something starts, fetch what comes after it.
- if let PlayerEvent::Playing { track_id, .. } = &event {
- preload_after(&player, &uri_string(track_id));
+ // Warm up the next track — but not the instant this one
+ // starts.
+ //
+ // Preloading on the first note meant a run of skips fired a
+ // burst of audio-key requests, Spotify refused them
+ // ("error audio key"), and librespot went on to decode the
+ // still-encrypted bytes: megabytes of noise through the
+ // decoder, thousands of log lines, and an app that looked
+ // frozen. A few seconds in, a track is one the listener is
+ // actually on, and a skipped-past track asks for nothing.
+ if let PlayerEvent::PositionChanged {
+ track_id,
+ position_ms,
+ ..
+ } = &event
+ {
+ let uri = uri_string(track_id);
+ if *position_ms > PRELOAD_AFTER_MS && preloaded.as_deref() != Some(&uri) {
+ preload_after(&player, &uri);
+ preloaded = Some(uri);
+ }
}
let (kind, uri, position_ms) = match event {
@@ -684,6 +711,49 @@ static CONTEXT_URI: Mutex<String> = Mutex::new(String::new());
/// [`preload_after`].
static QUEUE: Mutex<Vec<String>> = Mutex::new(Vec::new());
+/// How much of the phone the cached audio may take: 512 MB.
+const AUDIO_CACHE_LIMIT: u64 = 512 * 1024 * 1024;
+
+/// Deletes the temporary files left behind by downloads that never finished.
+///
+/// librespot writes each download to a `.tmp…` file beside the cache and
+/// renames it when it completes; a skip mid-download leaves the temporary file
+/// where it is, several megabytes at a time, for ever.
+fn sweep_stale_downloads(dir: &str) {
+ let Ok(entries) = std::fs::read_dir(dir) else {
+ return;
+ };
+ let mut removed = 0;
+ for entry in entries.flatten() {
+ let name = entry.file_name();
+ let Some(name) = name.to_str() else { continue };
+ if !name.starts_with(".tmp") {
+ continue;
+ }
+ // Only the ones nothing is writing any more. An hour is far longer than
+ // any download and short enough that they do not pile up.
+ let stale = entry
+ .metadata()
+ .and_then(|meta| meta.modified())
+ .map(|modified| {
+ modified
+ .elapsed()
+ .map(|age| age.as_secs() > 3600)
+ .unwrap_or(false)
+ })
+ .unwrap_or(false);
+ if stale && std::fs::remove_file(entry.path()).is_ok() {
+ removed += 1;
+ }
+ }
+ if removed > 0 {
+ log::info!("swept {removed} unfinished downloads");
+ }
+}
+
+/// How far into a track its successor is fetched, in milliseconds.
+const PRELOAD_AFTER_MS: u32 = 5_000;
+
/// Warms up the track after `uri`, so a skip does not start from nothing.
///
/// librespot preloads on its own, but only in the last thirty seconds of a
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 30ded4b..4ae4377 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -27,7 +27,19 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *mut c_void) -> jint {
android_logger::init_once(
android_logger::Config::default()
.with_max_level(log::LevelFilter::Info)
- .with_tag("spotcore"),
+ .with_tag("spotcore")
+ // Symphonia warns per frame while it resyncs, and a stream it
+ // cannot make sense of produced four thousand lines in a few
+ // seconds — enough logging to be felt as the app stalling. The
+ // errors still come through.
+ .with_filter(
+ android_logger::FilterBuilder::new()
+ .filter_level(log::LevelFilter::Info)
+ .filter_module("symphonia_bundle_mp3", log::LevelFilter::Error)
+ .filter_module("symphonia_core", log::LevelFilter::Error)
+ .filter_module("symphonia_format_ogg", log::LevelFilter::Error)
+ .build(),
+ ),
);
}