react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

fix(android): add next prev player commands

Open sohamnakhare opened this issue 3 months ago • 7 comments

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.

sohamnakhare avatar Sep 16 '25 15:09 sohamnakhare

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

tomKFM avatar Sep 18 '25 16:09 tomKFM

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 avatar Sep 19 '25 05:09 sohamnakhare

@tomKFM which lines did you have to remove ?

sohamnakhare avatar Sep 20 '25 15:09 sohamnakhare

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 avatar Sep 21 '25 14:09 tomKFM

@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)

tomKFM avatar Sep 21 '25 14:09 tomKFM

@tomKFM committed your suggestions.

sohamnakhare avatar Sep 21 '25 15:09 sohamnakhare

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.

puckey avatar Sep 23 '25 18:09 puckey