cordova-music-controls-plugin
cordova-music-controls-plugin copied to clipboard
Different music-controls-media-button events
Hi, music-controls-media-button works great but wouldn't it be better to send the keyCode, for example, as a second parameter to the "MusicControls.subscribe(events)" function since the variable "KeyEvent event" in MusicControlsBroadcastReceiver.java already has that value?
Then one could have different actions for example: KEYCODE_MEDIA_PREVIOUS KEYCODE_MEDIA_NEXT
My car acts as a bluetooth headset for my phone and all media control keys just fire the music-controls-media-button event and I can't differentiate the prev/next event from play/pause event.
I totally agree with this. Need to see this feature.
Sorry for the delay.
I also agree with you. I'll look at this. However, I have nothing to do tests with that...
So you would like that the callback gives you the integer event.getKeyCode()
(the significations of the integers are given here) ?
The best way to do it would be, as you said, to add a second integer parameter to the callback function. However, it would requires to do lots of changes (and I don't have the competences to do it for iOS and windows...).
So I can propose you a "temporary fix". I can add a switch
here which will distinguish between the most relevant values of the keyCode. In our case of music-control plugin, that would typically be play/pause prev/next, volume up/down ... The new message return would be then of the form "music-controls-media-button-play"
.
Does it look ok for you ?
If yes, I create a new branch for you to test it ;)
Thank you for looking into it. Yes I can test it for you.
I just created a new branch. It handles the most common (I guess) keyEvents, see here. Can you give a try and tell me if the event created by your remote are working ? Thank you.
Did a quick test with the new branch. Play, pause, prev and next buttons worked in my car. Didn't have other buttons to test.
Also, seemed to still work with a basic wired headphones pause button.
The car computer also likes to show album, track name and current position. Haven't researched how one would go about updating those. Now seems to pick the last played track name from other applications.
Hi guys, I would like to test this too. However, I'm using Ionic2 Native. Will this be added to the Ionic2 Native github too?
Hi, I do not know how the ionic team update their "wrappers" for Cordova plugins, so I guess that you'll have to wait. Can you test the plugin "outside" of ionic native ?
@Corrodian : great ! I'll see if I can add some more events...
Tested it and it works in the car. Not working on my headsets though. I tested it on an Android phone. There is also no need to update the ionic native wrapper, because it is using the same existing method.
Ok good. I merged it to the master branch. I also add some more keycodes: your headset button may be recognized now. All keycodes are listed here. I added the most relevant. If you have suggestions about other keycodes, I can add them !
For the moment, when you press "next" or "previous" on your headset, you only get a "music-controls-media-button" message right ?