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.

Report a listen when it is paused, not only when it ends

Lelonio2f54f9c48997
diff --git a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
index e618c96..76f7bd1 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/native/src/engine.rs b/native/src/engine.rs
index d630688..718209f 100644
--- a/native/src/engine.rs
+++ b/native/src/engine.rs
@@ -431,14 +431,45 @@ impl History {
..
} => self.start(uri_string(track_id), *position_ms),
- PlayerEvent::Paused { position_ms, .. }
- | PlayerEvent::PositionChanged { position_ms, .. }
+ PlayerEvent::PositionChanged { position_ms, .. }
| PlayerEvent::Seeked { position_ms, .. } => {
if let Some(playing) = self.current.as_mut() {
playing.position_ms = *position_ms;
}
}
+ // A pause ends the stretch that was being listened to.
+ //
+ // Reported straight away rather than held until the track finishes,
+ // because most of the time it never does: the track is paused, the
+ // app is left, and the process goes away with the listen still
+ // sitting in memory. That is why only one of a session's tracks
+ // ever reached the account's history.
+ //
+ // Resuming opens a *new* playback at the position it resumes from,
+ // so what is reported is always a stretch that really was heard —
+ // never one invented to make a pause look like a full play.
+ PlayerEvent::Paused { position_ms, .. } => {
+ if let Some(playing) = self.current.as_mut() {
+ playing.position_ms = *position_ms;
+ }
+ // Not when the pause is the track running out: the end of a
+ // track is reported as one, and reporting it here first would
+ // take the completed listen away and leave a stopped one in its
+ // place.
+ let at_end = self
+ .current
+ .as_ref()
+ .map(|playing| {
+ playing.duration_ms > 0
+ && playing.position_ms + END_MARGIN_MS >= playing.duration_ms
+ })
+ .unwrap_or(false);
+ if !at_end {
+ self.finish(EndReason::EndPlay);
+ }
+ }
+
// Ran to the end: the one that counts as a full listen.
PlayerEvent::EndOfTrack { .. } => self.finish(EndReason::TrackDone),
PlayerEvent::Stopped { .. } => self.finish(EndReason::EndPlay),
@@ -501,6 +532,13 @@ impl History {
let Some(playing) = self.current.take() else {
return;
};
+ // A stretch too short to have been listened to at all — a pause landing
+ // in the same instant as the start, a track that failed to open.
+ if playing.position_ms.saturating_sub(playing.start_ms) < MIN_LISTEN_MS
+ && !matches!(reason, EndReason::TrackDone)
+ {
+ return;
+ }
// Running off the end means the whole track was heard, whatever the
// last position report happened to say.
let end_ms = match reason {
@@ -527,6 +565,12 @@ impl History {
}
}
+/// How close to the end counts as the track finishing rather than being paused.
+const END_MARGIN_MS: u32 = 2_000;
+
+/// Below this, a stretch is a mis-tap rather than a listen.
+const MIN_LISTEN_MS: u32 = 1_000;
+
/// A track's gid in hex, which is what the events carry — not the base62 id.
fn hex_id(uri: &str) -> String {
match SpotifyUri::from_uri(uri) {