I am using cordova-plugin-music-controls 2 and have created a media panel that works correctly. But The app can't handle button presses on the Bluetooth speaker, but handles it in notifications. How do I control multimedia using a Bluetooth speaker?
var data = {
track: 'Test',
artist: 'Test',
isPlaying: false,
playIcon: 'media_play',
pauseIcon: 'media_pause',
prevIcon: 'media_prev',
nextIcon: 'media_next',
closeIcon: 'media_close',
notificationIcon: 'notification'
};
var nxt = 1;
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
console.log("device ready");
mediaNotification();
}
function play() {
data = {
track: 'Test',
artist: nxt,
isPlaying: false,
playIcon: 'media_play',
pauseIcon: 'media_pause',
prevIcon: 'media_prev',
nextIcon: 'media_next',
closeIcon: 'media_close',
notificationIcon: 'notification'
}
MusicControls.create(data
);
nxt = nxt + 1;
}
function mediaNotification() {
function musicControlsEvent(action) {
const message = JSON.parse(action).message;
switch (message) {
case 'music-controls-next':
play();
break;
case 'music-controls-previous':
break;
case 'music-controls-next':
play();
console.log("play");
break;
case 'music-controls-pause':
break;
case 'music-controls-play':
play();
break;
case 'music-controls-destroy':
break;
case 'music-controls-toggle-play-pause':
play();
break;
case 'music-controls-seek-to':
break;
case 'music-controls-media-button':
play();
break;
case 'music-controls-media-button-stop':
play();
break;
case 'music-controls-headset-unplugged':
// Do something
break;
case 'music-controls-headset-plugged':
// Do something
break;
default:
break;
}
}
MusicControls.create(data
);
MusicControls.subscribe(musicControlsEvent);
MusicControls.listen();
}
I have tried using different Bluetooth devices, but there is no result.