ghenry22 / cordova-plugin-music-controls2

A Cordova plugin displaying music controls in notifications (cordova-plugin-music-controls)
MIT License
59 stars 60 forks source link

iOS: headphone button event doesn't received #77

Closed kncsdev closed 2 years ago

kncsdev commented 2 years ago

Hi,

In ios, pressing the button(togglePlayPause) on the earpods does not receive an event. It was exactly until yesterday, but it didn't work today. Since the event itself cannot be received, the logic cannot be implemented.

env

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    // Cordova is now initialized. Have fun!

    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    document.getElementById('deviceready').classList.add('ready');

    MusicControls.create({}, console.log('Success'), console.log('Fail'));

    // Register callback
    MusicControls.subscribe(function(action){
        const message = JSON.parse(action).message;   //miss typo
        switch(message) {
            case 'music-controls-next':
            case 'music-controls-previous':
            case 'music-controls-pause':
            case 'music-controls-play':
                console.log("next/prev/pause/play@@@");
                break;
            case 'music-controls-toggle-play-pause' :
                console.log("toggle@@");
                break;
            default:
                console.log("??");
                break;
        }
    });

    MusicControls.listen();
}

When built with xcode, the app runs fine without any errors, but when the button is pressed, the event is not received. What I need is a toggle button, is there a way to bypass it?

Thanks!