fix(android): add next prev player commands
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.
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
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.
@tomKFM which lines did you have to remove ?
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
@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 committed your suggestions.
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.