diff --git a/android/src/main/java/com/doublesymmetry/kotlinaudio/models/CustomCommandButton.kt b/android/src/main/java/com/doublesymmetry/kotlinaudio/models/CustomCommandButton.kt index 9b48e3214..821d6eadc 100644 --- a/android/src/main/java/com/doublesymmetry/kotlinaudio/models/CustomCommandButton.kt +++ b/android/src/main/java/com/doublesymmetry/kotlinaudio/models/CustomCommandButton.kt @@ -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(), ); } \ No newline at end of file diff --git a/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt b/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt index 60b68719d..ae975b16f 100644 --- a/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt +++ b/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt @@ -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)) } diff --git a/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt b/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt index b495b5a98..95d076699 100644 --- a/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +++ b/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt @@ -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 @@ -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 -> @@ -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 } @@ -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)