Skip to content

Conversation

@sohamnakhare
Copy link

Why / What Problem Does It Solve

Previously, the command builder didn’t support “skip to next” and “skip to previous” remote/media control commands.

This meant that remote controls (e.g. notification controls, lock screen, media buttons) couldn’t trigger next or previous track actions via the command builder.

The commit adds in those capabilities so that clients using the command builder will have those actions available.

Implications / Effects

After this commit, when building PlayerCommandBuilder, users can include “next” and “previous” player commands.

Remote events (or media buttons) that request skip next or skip previous can be wired up using these commands.

Improves usability: users can now navigate tracks via remote controls or UI elements that rely on “next/prev” capabilities.

@tomKFM
Copy link

tomKFM commented Sep 18, 2025

next, previous and pause works great, but interestingly i still cannot play the music. And I also had to remove lines to make it work because it wouldnt compile

@sohamnakhare
Copy link
Author

sohamnakhare commented Sep 19, 2025

next, previous and pause works great, but interestingly i still cannot play the music.

@tomKFM Here COMMAND_PLAY_PAUSE is added, if pause works, play would also work just that you'd have to detect the player state and call either play / pause.

@sohamnakhare sohamnakhare changed the title add next prev player commands fix(android): add next prev player commands Sep 20, 2025
@sohamnakhare
Copy link
Author

@tomKFM which lines did you have to remove ?

@tomKFM
Copy link

tomKFM commented Sep 21, 2025

react-native-track-player/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt:60:41 Unresolved reference 'NEXT'.
react-native-track-player/android/src/main/java/com/doublesymmetry/kotlinaudio/service/MusicService.kt:61:41 Unresolved reference 'PREVIOUS'.

had to remove those lines

Concerning the pause/play bug, I know it should work. But it doesnt. I can only pause, but not play
This bug only occurs in the "extended" media notification, which only exist with oxygenOS ? Not sure about that
Im investigating on my own

By the way, my device is OnePlus 13, android 15

@tomKFM
Copy link

tomKFM commented Sep 21, 2025

@sohamnakhare Ok, turns out that in oxygenOS, the play button in the expanded view always sends KEYCODE_MEDIA_PLAY_PAUSE instead of distinguishing between play and pause actions. And when called, weirdly it cannot play back the track

I fixed that by simply modifying

emit(if (!player.playWhenReady) MusicEvents.BUTTON_PLAY else MusicEvents.BUTTON_PAUSE)

at line 835 at trackplayer/service/MusicService.kt, instead of emit(MusicEvents.BUTTON_PLAY_PAUSE)

@sohamnakhare
Copy link
Author

@tomKFM committed your suggestions.

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_PLAY_PAUSE)
Copy link

@tomKFM tomKFM Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emit(if (!player.playWhenReady) MusicEvents.BUTTON_PLAY else MusicEvents.BUTTON_PAUSE)

(my bad, i modifyed my comment since then, but here BUTTON_PAUSE instead of BUTTON_PLAY_PAUSE seems more natural)

@puckey
Copy link
Collaborator

puckey commented Sep 23, 2025

Before approving this, I want to make sure we can't fix things using the custom controls which was removed in this pr. The reason for the custom controls code is to allow customising of icons in older versions of Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants