Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,5 @@ enum class CustomCommandButton(
.setSessionCommand(SessionCommand("JUMP_FORWARD", Bundle()))
.setIconResId(R.drawable.media3_icon_skip_forward)
.build(),
),
PREVIOUS(
customAction = "PREVIOUS",
capability = Capability.SKIP_TO_NEXT,
commandButton = CommandButton.Builder()
.setDisplayName("Previous")
.setSessionCommand(SessionCommand("PREVIOUS", Bundle()))
.setIconResId(R.drawable.media3_icon_previous)
.build(),
),
NEXT(
customAction = "NEXT",
capability = Capability.SKIP_TO_PREVIOUS,
commandButton = CommandButton.Builder()
.setDisplayName("Next")
.setSessionCommand(SessionCommand("NEXT", Bundle()))
.setIconResId(R.drawable.media3_icon_next)
.build(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class MusicService : HeadlessJsMediaService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
onStartCommandIntentValid = intent != null
Timber.d("onStartCommand: ${intent?.action}, ${intent?.`package`}")
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
// HACK: this is not supposed to be here. I definitely screwed up. but Why?
onMediaKeyEvent(intent)
}
// }
// HACK: Why is onPlay triggering onStartCommand??
if (!commandStarted) {
commandStarted = true
Expand Down Expand Up @@ -290,12 +290,33 @@ class MusicService : HeadlessJsMediaService() {
playerCommandsBuilder.add(Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)
}

Capability.SKIP_TO_NEXT -> {
playerCommandsBuilder.add(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)
playerCommandsBuilder.add(Player.COMMAND_SEEK_TO_NEXT)
}

Capability.SKIP_TO_PREVIOUS -> {
playerCommandsBuilder.add(Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)
playerCommandsBuilder.add(Player.COMMAND_SEEK_TO_PREVIOUS)
}

Capability.JUMP_FORWARD -> {
playerCommandsBuilder.add(Player.COMMAND_SEEK_FORWARD)
}

Capability.JUMP_BACKWARD -> {
playerCommandsBuilder.add(Player.COMMAND_SEEK_BACK)
}

else -> {}
}
}

customLayout = CustomCommandButton.entries
.filter { notificationCapabilities.contains(it.capability) }
.filter { it != CustomCommandButton.NEXT && it != CustomCommandButton.PREVIOUS }
.map { c -> c.commandButton }

val sessionCommandsBuilder =
MediaSession.ConnectionResult.DEFAULT_SESSION_AND_LIBRARY_COMMANDS.buildUpon()
customLayout.forEach { v ->
Expand Down Expand Up @@ -935,8 +956,6 @@ class MusicService : HeadlessJsMediaService() {
when (command.customAction) {
CustomCommandButton.JUMP_BACKWARD.customAction -> { it.seekBack() }
CustomCommandButton.JUMP_FORWARD.customAction -> { it.seekForward() }
CustomCommandButton.NEXT.customAction -> { it.seekToNext() }
CustomCommandButton.PREVIOUS.customAction -> { it.seekToPrevious() }
}
}
return super.onCustomCommand(session, controller, command, args)
Expand Down