Open vickynathaiya opened 7 years ago
Hi @vickynathaiya, Are the volume up/down the only events that are not triggered ?
Hi @homerours yes, actually i am working with headset events. headset plugged, unplugged and headset hook event are working properly. But i don't know why volume up and down not working even with headset and without headset
The code above looks like it won't work. The action
coming back is in JSON format. You'll need to retrieve the action from the message parameter after parsing the JSON.
// action looks like this as a string: '{\"message\":\"music-controls-media-button-volume-down\"}'
const eventType = JSON.parse(action).message
Then can you use your switch
statement on eventType
.
I'm having problems with this too, events from the headphone buttons doesn't fire. Only plug and unplug events are fired.
` function events(action) {
const message = JSON.parse(action).message;
switch(message) {
case 'music-controls-next':
// Do something
break;
case 'music-controls-previous':
// Do something
break;
case 'music-controls-pause':
// Do something
break;
case 'music-controls-play':
// Do something
break;
case 'music-controls-destroy':
// Do something
break;
// Headset events (Android only)
// All media button events are listed below
case 'music-controls-media-button' :
// Do something
break;
case 'music-controls-headset-unplugged':
// Do something
break;
case 'music-controls-headset-plugged':
// Do something
break;
default:
break;
}
};
MusicControls.subscribe(events);
MusicControls.listen();`
@Sbissa Your cases are not sufficient to cover play and pause events from headset. Listen to more events.
Something like this.
`
this._ngZone.run(() => {
switch(message) {
case 'music-controls-next':
case 'music-controls-skip-forward':
self.onSkipForwardFromOutside();
// Do something
break;
case 'music-controls-previous':
case 'music-controls-skip-backward':
self.onSkipBackwardFromOutside();
// Do something
break;
case 'music-controls-pause':
case 'music-controls-toggle-play-pause' :
case 'music-controls-play':
self.onPlayFromOutside();
break;
case 'music-controls-seek-to':
// Do something
break;
// Headset events (Android only)
// All media button events are listed below
case 'music-controls-media-button-music':
case 'music-controls-media-button-headset-hook':
case 'music-controls-media-button-pause':
case 'music-controls-media-button-play':
case 'music-controls-media-button-play-pause':
this.registerTap(()=>{this.onPlayFromOutside()},()=>{this.onRepeatWithoutTouch()},CONFIG.DOUBLE_TAP_DELAY);
console.log(action);
break;
case 'music-controls-media-button-skip-forward':
case 'music-controls-media-button-step-forward':
case 'music-controls-media-button-meta-right':
case 'music-controls-media-button-next':
self.onSkipForwardFromOutside();
break;
case 'music-controls-media-button-skip-backward':
case 'music-controls-media-button-step-backward':
case 'music-controls-media-button-meta-left':
case 'music-controls-media-button-previous':
self.onSkipBackwardFromOutside();
break;
case 'music-controls-headset-unplugged':
self.pause();
// Do something
break;
case 'music-controls-headset-plugged':
self.pause();
// Do something
break;
case 'music-controls-media-button-fast-forward':
case 'music-controls-media-button-rewind':
break;
default:
break;
}
});`
@quran-memorizer the problem isn't the switch. I'm not receiving any events, only the plug and unplug. The only message i've got from the subscribe is the plug and unplug when i press the buttons from the headset nothing happens
@Sbissa - this should be resolved in the latest release, try installing from the github repo directly as NPM is out of date currently.
Yeah, currently @homerours is the only one who has access to publish the pacakge to NPM.
Thanks guys, i used the github repo and works now!
Hi, i have tried many way to detect volume up and down but its not working. i don't know why. My code is as below. please let me know where i am wrong.
export class HomePage {
alert(JSON.stringify(action)); switch(action) { case 'music-controls-next': alert("Next"); break; case 'music-controls-previous': // Do something alert("Previous"); break; case 'music-controls-pause': // Do something alert("Pause"); break; case 'music-controls-play': // Do something alert("Play"); break; case 'music-controls-destroy': // Do something break;
}
});
musicControls.listen(); // activates the observable above
//musicControls.updateIsPlaying(true);
}
}