Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -57,8 +57,6 @@ class MusicService : MediaLibraryService() {
when (customCommand.customAction) {
CustomCommandButton.JUMP_BACKWARD.customAction -> { player.seekBack() }
CustomCommandButton.JUMP_FORWARD.customAction -> { player.seekForward() }
CustomCommandButton.NEXT.customAction -> { player.seekToNext() }
CustomCommandButton.PREVIOUS.customAction -> { player.seekToPrevious() }
}
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
}
Expand Down
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,32 @@ 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) }
.map { c -> c.commandButton }

val sessionCommandsBuilder =
MediaSession.ConnectionResult.DEFAULT_SESSION_AND_LIBRARY_COMMANDS.buildUpon()
customLayout.forEach { v ->
Expand Down Expand Up @@ -812,7 +832,9 @@ class MusicService : HeadlessJsMediaService() {
if (keyEvent?.action == KeyEvent.ACTION_DOWN) {
return when (keyEvent.keyCode) {
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> {
emit(MusicEvents.BUTTON_PLAY_PAUSE)
// in oxygenOS, the play button in the expanded view always sends KEYCODE_MEDIA_PLAY_PAUSE
// instead of distinguishing between play and pause actions
emit(if (!player.playWhenReady) MusicEvents.BUTTON_PLAY else MusicEvents.BUTTON_PAUSE)
true
}

Expand Down Expand Up @@ -935,8 +957,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