fix: notification skip/back drive the app queue
CI / build (push) Successful in 14m12s
CI / play (push) Successful in 3m20s

- advertise next/previous on a ForwardingPlayer so the notification and
  Android Auto show the buttons, and route them to the mood queue
- rename the preview section to 'Up next' with a clearer subtitle
- version 0.3.2
This commit is contained in:
TapTap committed 2026-11-18 19:14:05 +00:00
1 parent 2478505dba
commit e28e95fa2b
5 files changed
+49 -8

No files matched your search

@@ -9,6 +9,8 @@ import android.view.KeyEvent
import androidx.core.content.IntentCompat
import androidx.media3.common.AudioAttributes
import androidx.media3.common.C
import androidx.media3.common.ForwardingPlayer
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
@@ -38,7 +40,7 @@ class PlaybackService : MediaSessionService() {
override fun onCreate() {
super.onCreate()
val player = ExoPlayer.Builder(this)
val exoPlayer = ExoPlayer.Builder(this)
.setAudioAttributes(
AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
@@ -52,6 +54,44 @@ class PlaybackService : MediaSessionService() {
setWakeMode(C.WAKE_MODE_NETWORK)
}
// ExoPlayer holds one item at a time; the queue lives in the app. Advertise
// next/previous so the notification and Android Auto show the buttons and
// route them to the queue instead of seeking inside the single item.
val player = object : ForwardingPlayer(exoPlayer) {
override fun getAvailableCommands(): Player.Commands =
super.getAvailableCommands().buildUpon()
.addAll(
Player.COMMAND_SEEK_TO_NEXT,
Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM,
Player.COMMAND_SEEK_TO_PREVIOUS,
Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM,
)
.build()
override fun isCommandAvailable(command: Int): Boolean =
command == Player.COMMAND_SEEK_TO_NEXT ||
command == Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM ||
command == Player.COMMAND_SEEK_TO_PREVIOUS ||
command == Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM ||
super.isCommandAvailable(command)
override fun seekToNext() {
if (!PlaybackCommands.next()) super.seekToNext()
}
override fun seekToNextMediaItem() {
if (!PlaybackCommands.next()) super.seekToNextMediaItem()
}
override fun seekToPrevious() {
if (!PlaybackCommands.previous()) super.seekToPrevious()
}
override fun seekToPreviousMediaItem() {
if (!PlaybackCommands.previous()) super.seekToPreviousMediaItem()
}
}
val sessionActivity = PendingIntent.getActivity(
this,
0,