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:
parent
1766283cd2
commit
a44f0bce35
1 changed files with 14 additions and 5 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue