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.

Music can survive the app being swiped away

Lelonio951f8bf15793
diff --git a/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt b/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
index 5d3eb92..386119a 100644
--- a/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
+++ b/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
@@ -84,6 +84,24 @@ class PreferencesStore(context: Context) {
prefs.edit().putBoolean(KEY_CANVAS, value).apply()
}
+ private val _keepPlayingOnClose = MutableStateFlow(prefs.getBoolean(KEY_KEEP_PLAYING, false))
+
+ /**
+ * Whether the music survives the app being swiped out of the recents.
+ *
+ * Off by default, and deliberately: a player that goes on after the app has
+ * been dismissed is a player the gesture did not reach, and the shade is
+ * then the only way to stop it. But the same gesture is easy to make by
+ * accident, and losing the song for it is worse for the people who asked
+ * (#27) — so it is a choice rather than a rule.
+ */
+ val keepPlayingOnClose: StateFlow<Boolean> = _keepPlayingOnClose.asStateFlow()
+
+ fun setKeepPlayingOnClose(value: Boolean) {
+ _keepPlayingOnClose.value = value
+ prefs.edit().putBoolean(KEY_KEEP_PLAYING, value).apply()
+ }
+
private val _autoplayInfinite = MutableStateFlow(prefs.getBoolean(KEY_AUTOPLAY_INFINITE, false))
/** Whether playback automatically appends similar tracks when reaching queue end. */
@@ -226,6 +244,7 @@ class PreferencesStore(context: Context) {
const val KEY_DEVICE_ID = "device_id"
const val KEY_ONBOARDED = "onboarded"
const val KEY_CANVAS = "canvas_enabled"
+ const val KEY_KEEP_PLAYING = "keep_playing_on_close"
const val KEY_AUTOPLAY_INFINITE = "autoplay_infinite"
const val KEY_TRIM_SILENCE = "trim_silence"
const val KEY_SKIP_FADE = "skip_fade"
diff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
index 565f9df..5b680dd 100644
--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
@@ -1636,6 +1636,14 @@ class PlaybackService : MediaLibraryService() {
// to stop it did nothing, and what was left was a notification the user
// had already tried to get rid of.
//
+ // Unless the listener has asked for the music to survive the gesture:
+ // a swipe is easy to make by accident, and losing the song for it is
+ // what #27 asked about. The notification is still there to stop it.
+ if (container.preferences.keepPlayingOnClose.value && player.isPlaying) {
+ android.util.Log.i(TAG, "task removed while playing; kept alive by the setting")
+ return
+ }
+
// 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.