Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Stop playback when the app is swiped away
Lelonio290fc0ed2597
diff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.ktindex d4a66fe..2148ffb 100644--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt@@ -545,13 +545,20 @@ class PlaybackService : MediaLibraryService() {sessionoverride fun onTaskRemoved(rootIntent: Intent?) {+ // Saved first: this is the last chance to record where the track was,+ // and stopping is what makes the position worth having.runCatching { savePlayback() }- // Swiping the app away should not kill audio mid-track, but it should- // stop an idle service from lingering in the notification shade.- val current = session?.player- if (current == null || !current.isPlaying) {- stopSelf()- }+ // Swiping the app away stops it. The service used to survive a swipe+ // while something was playing, on the grounds that killing audio+ // mid-track is rude, but a player that goes on after its app has been+ // dismissed is a player the gesture did not reach: the one obvious way+ // to stop it did nothing, and what was left was a notification the user+ // had already tried to get rid of.+ //+ // Media3's own helper rather than a bare stopSelf: it pauses every+ // player attached to the service first, so the engine is told to stop+ // instead of being cut off when onDestroy releases it.+ pauseAllPlayersAndStopSelf()}override fun onDestroy() {