Jason Custer
unread,Mar 25, 2020, 2:25:20 PM3/25/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DroidScript
Hi again!
Got another question for the learned scolars of the group. Yes, I mean you. Is there a way to detect when headphones, bluetooth/wired, are removed? There is an android action I tried to receive, "android.intent.action.HEADSET_PLUG", but I don't receive any intents that aren't specifficly for my app. I also tried using plain javascript, but the changed event doesn't fire. Code is below. I just want to pause audio when headphones are removed. I'm using CreateMediaPlayer.
While we're on the subject, is there a way to catch media buttons when the DS app is not on the screen? IE, checking email, want to pause the music. I'm aware of SetOnKey, but don't think it works when the app doesn't have focus.
Failed JS code.
//this never fires.
navigator.mediaDevices.addEventListener('devicechange', () => {
alert("Device changed.");
navigator.mediaDevices.enumerateDevices()
.then(devices => {
// Check the connected devices
alert(JSON.stringify(devices));
});
});
OnStart = function() {
//this works, sortof, output below.
navigator.mediaDevices.enumerateDevices()
.then(devices => {
// Check the connected devices
alert(JSON.stringify(devices));
});
} //OnStart
//the audioout kind of devices never change, labels are generic, "default".
//output:
[{"deviceId":"default","kind":"audioinput","label":"","groupId":"058f6023048c457fb3c2aeeda368e60baed15063b65054bc3353feee02842c53"},{"deviceId":"4b76aae98398e93c8b633a2f2d60a3d5b2c9ca883e9a19180b48d51c7a74812e","kind":"audioinput","label":"","groupId":"21acdfb4d858ed548d5437cd8b0c9c9f3ce3caae4bb1729e9738f7c0380ae9c7"},{"deviceId":"dfe27e477cb5b2817fb86986d8c92c9b8ed7c629dede9ead4e761d459895a5e6","kind":"audioinput","label":"","groupId":"cf69cb8333f0175dddfc0079ed59af4e54c8d949001e02d2462f3d4a8b70b5ed"},{"deviceId":"c38a32aeb7deae0b55f412ae42682012ba47330c8f9280e3986e90141e6de1ad","kind":"audioinput","label":"","groupId":"ed2e70019013a3760327e55aa3160651ad66fe9ce6cd503756edeadb2f33675e"},{"deviceId":"dfe27e477cb5b2817fb86986d8c92c9b8ed7c629dede9ead4e761d459895a5e6","kind":"videoinput","label":"","groupId":"4901bb3e1486b84be3729fc197ba169b2029d6bfefd4a9f60ce0553d821ba72a"},{"deviceId":"c38a32aeb7deae0b55f412ae42682012ba47330c8f9280e3986e90141e6de1ad","kind":"videoinput","label":"","groupId":"e4bc7b801e55924faf2434ebedf09b62a867b4fb81d1c3cc6cae2ec42f00e597"},{"deviceId":"e5a2c3b65adaec5dd3b1e5e42a2d826136d07fa7381b6f9c927e4e7a918aac1a","kind":"videoinput","label":"","groupId":"dd33f0a32941d57657cd793b489fd6435e794968c35f04ffd054cc51aa12606d"},{"deviceId":"4b76aae98398e93c8b633a2f2d60a3d5b2c9ca883e9a19180b48d51c7a74812e","kind":"videoinput","label":"","groupId":"2c35f647e4e4effc1d9242daf085b8658b809f04e39495b0f0e0482b078a9db1"},{"deviceId":"default","kind":"audiooutput","label":"","groupId":"default"}]
Please forgive the formatting. Extra credit for a working example.
I'd like to do something like this.
onDeviceChange(didRemove) { //onDeviceChange not a real event, yet.
alert("you changed your audio output device. " + didRemove ? "removed" : "added");
}