playback: stop playback on task removal if paused

This is apparently the standard behavior that media apps should use to
allow the foreground state to be exited. I personally don't want to
make it really unilateral like that, so if playback is already ongoing
I'll keep the foreground state going.
This commit is contained in:
Alexander Capehart 2024-01-15 16:23:04 -07:00
parent 1766283cd2
commit a44f0bce35
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -191,7 +191,12 @@ class PlaybackService :
override fun onBind(intent: Intent): IBinder? = null
// TODO: Implement task removal (Have to radically alter state saving to occur at runtime)
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
if (!playbackManager.progression.isPlaying) {
endSession()
}
}
override fun onDestroy() {
super.onDestroy()
@ -631,6 +636,13 @@ class PlaybackService :
.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC))
}
private fun endSession() {
// This session has ended, so we need to reset this flag for when the next
// session starts.
hasPlayed = false
foregroundManager.tryStopForeground()
}
/**
* A [BroadcastReceiver] for receiving playback-specific [Intent]s from the system that require
* an active [IntentFilter] to be registered.
@ -687,10 +699,7 @@ class PlaybackService :
ACTION_EXIT -> {
logD("Received exit event")
playbackManager.playing(false)
// This session has ended, so we need to reset this flag for when the next
// session starts.
hasPlayed = false
foregroundManager.tryStopForeground()
endSession()
}
WidgetProvider.ACTION_WIDGET_UPDATE -> {
logD("Received widget update event")