-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(android): add next prev player commands #2517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(android): add next prev player commands #2517
Conversation
android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
Outdated
Show resolved
Hide resolved
|
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 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'. 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 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 at line 835 at trackplayer/service/MusicService.kt, instead of |
|
@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) |
There was a problem hiding this comment.
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)
|
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. |
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.