Open torch2424 opened 9 years ago
Cant be done with local broadcast manager since pendingintents cannot be used with them
This happens when using notification controls. You can look how other Open Source media players handle them.
For example, Encore: https://github.com/fastbootmobile/encore/blob/master/src/main/java/com/fastbootmobile/encore/service/ServiceNotification.java https://github.com/fastbootmobile/encore/blob/master/src/main/java/com/fastbootmobile/encore/service/NotifActionService.java
VLC also is open source. Also Apollo.
It probably has something to do with passing null to intent:
Intent prev = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent prevEvent = new KeyEvent(0, 0,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
prev.setAction(Intent.ACTION_MEDIA_BUTTON);
Both players seem to be passing a class that handles the controls: Encore:
Intent intent = new Intent(context, NotifActionService.class);
intent.setAction(ACTION_TOGGLE_PAUSE);
return intent;
Apollo:
final ComponentName serviceName = new ComponentName(mService, MusicPlaybackService.class);
...
// Play and pause
action = new Intent(MusicPlaybackService.TOGGLEPAUSE_ACTION);
action.setComponent(serviceName);
@rancidfrog oh rad! Honestly, I've been looking around for open source media players, but I had trouble finding them, thank you for leading me in the right direction!
Thank you for the help. You're more than welcome to go ahead and make a pull request, as I've been busy with school and work so updates on my end have been slow sadly.
But either way, thank you for the help! :)
Also, @rancidfrog I noticed that this issue also happens if you use a rooted phone with a rom with music playback controls, such as cyanogenmod, it will call the stock player and things
And again thank you o much for your help, I've had this bug forever haha! And please excuse my terrible code, I've been writing and rewriting this here and there since I first started getting into app development haha
Try using a local brodcast manager https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html