Giter Club home page Giter Club logo

Comments (16)

CesarOliveira avatar CesarOliveira commented on June 23, 2024 1

I have the same issue here on iOS:
`
this.musicControls.subscribe().subscribe(action => {

    function events(action) {
      const message = JSON.parse(action).message;
      switch(message) {
        case 'music-controls-pause':
          this.pause();
          break;
        case 'music-controls-play':
          this.play();
          break;
        default:
          break;
      }
    }

});
`

When the phone is locked and I click in pause nothing happens, any thoughts?

from cordova-music-controls-plugin.

nadav12 avatar nadav12 commented on June 23, 2024

I solved it, it turns out I needed to add this lines after each event
MusicControls.updateIsPlaying(false/true); //toggles between play and pause
MusicControls.listen(); //continue to listen to events (only for one action/click until you call it again)

and you need to add this also after creation - MusicControls.listen();
It's working great for me..

from cordova-music-controls-plugin.

CesarOliveira avatar CesarOliveira commented on June 23, 2024

I already have the: MusicControls.listen(); but not working at all.

The cover, track, artist, ticker and all works fine, just the action of Pause (or Play) that I do not receive the callback in my actions to pause the song.

from cordova-music-controls-plugin.

CesarOliveira avatar CesarOliveira commented on June 23, 2024

@nadav12 can you post your code?

from cordova-music-controls-plugin.

nadav12 avatar nadav12 commented on June 23, 2024

here's a link I operated an angular function on each event
hope this helps

from cordova-music-controls-plugin.

nadav12 avatar nadav12 commented on June 23, 2024

Did you figured this out? I've done some big changes in the project and some the events are'nt called

from cordova-music-controls-plugin.

CesarOliveira avatar CesarOliveira commented on June 23, 2024

Not yet @nadav12

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

I have the same problem, play/pause event does not work using Ionic Native Music Controls and this plugin. I'm testing it with 1.4.1 plugin version (2.0 doesn't show buttons on IOS) , Ionic3, XCode 9 and iOS Simulator with 10.3 & 11.0, and an iPhone real Device with iOS 11.0. Play/Pause control event isn't fired.


       this.currentFile.play();
        this.myControls.destroy();
        this.myControls.create({
            track       : 'Example',   
            artist      : 'Example A',        
            cover       : '',   
            isPlaying   : true,        
            dismissable : true,   
            hasPrev   : false,   
            hasNext   : false,  
            hasClose  : true,  
            
            album       : '',   
            duration : 0, 
            elapsed : 0,
      
            ticker    : 'Now playing "example"'
           });

        this.myControls.subscribe().subscribe(action => {
            function events(action) {
                const message = JSON.parse(action).message;
                    switch(message) {
                        case 'music-controls-next':
                            console.log('music-controls-next');
                            break;
                        case 'music-controls-previous':
                            // Do something
                            break;
                        case 'music-controls-pause':
                            console.log('music-controls-pause');
                            this.controlAudio('pause');
                            break;
                        case 'music-controls-play':
                            console.log('music-controls-play');
                            this.controlAudio('play');
                            break;
                        case 'music-controls-destroy':
                            // Do something
                            break;

                        // External controls (iOS only)
                        case 'music-controls-toggle-play-pause' :
                                console.log('music-controls-toggle-play-pause');
                                break;
                        case 'music-controls-seek-to':
                        // Do something
                        break;
                        case 'music-controls-skip-forward':
                        // Do something
                        break;
                        case 'music-controls-skip-backward':
                        // Do something
                        break;

                        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;
                    }
            }
        });
        this.myControls.listen(); 
        this.myControls.updateIsPlaying(true);

from cordova-music-controls-plugin.

edotassi avatar edotassi commented on June 23, 2024

Try this:

this.myControls.subscribe().subscribe(action => {
                const message = JSON.parse(action).message;
                    switch(message) {
                        case 'music-controls-next':
                            console.log('music-controls-next');
                            break;
                        case 'music-controls-previous':
                            // Do something
                            break;
                        case 'music-controls-pause':
                            console.log('music-controls-pause');
                            this.controlAudio('pause');
                            break;
                        case 'music-controls-play':
                            console.log('music-controls-play');
                            this.controlAudio('play');
                            break;
                        case 'music-controls-destroy':
                            // Do something
                            break;

                        // External controls (iOS only)
                        case 'music-controls-toggle-play-pause' :
                                console.log('music-controls-toggle-play-pause');
                                break;
                        case 'music-controls-seek-to':
                        // Do something
                        break;
                        case 'music-controls-skip-forward':
                        // Do something
                        break;
                        case 'music-controls-skip-backward':
                        // Do something
                        break;

                        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;
            }
        });

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

@edotassi thanks, using your code on Device iOS 11 and on Simulator iOS9.3 when I click pause/play I get only this error in XCode9's console:
Error in Success callbackId: MusicControls1369790364 : SyntaxError: JSON Parse error: Unexpected identifier "music"

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

I’ve created a minimal ionic blank app from ionic starter, with Media stream (works) and Music Controls (not works), it’s available on github for testing :
https://github.com/fdambrosio/ionic-media-controls

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

I've found the error in the Docs:

the string with the 'message' is the same 'action' parameter, so

if I write:


this.myControls.subscribe().subscribe(action => {
                    switch(action) {
.......

it works O_O

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

I have to use 1.4.1 release, 2.x / 2.1.1 too is not working, play/pause event are not fired

from cordova-music-controls-plugin.

ghenry22 avatar ghenry22 commented on June 23, 2024

versions prior to 2.0.0 you need to use switch(action). Versions after 2.0.0 require you to parse.JSON first then switch.

I have submitted a PR to ionic native to update some errors in the documentation.

Version 2.1.4 (installed from the github repo as NPM is not currently updated) should work fine. I am using it with latest ionic-native with no issues. I don't use the play-pause-toggle. Just the play and pause events. My play and pause handlers in my app already deal with toggling anyway. I also never need to call the updateIsPlaying method personally.

from cordova-music-controls-plugin.

fdambrosio avatar fdambrosio commented on June 23, 2024

thanks @ghenry22 , I've tested 2.1.4 and it's working, but I need to do :

npm remove cordova-plugin-music-controls
npm install https://github.com/homerours/cordova-music-controls-plugin --save
ionic cordova plugin rm cordova-plugin-music-controls
ionic cordova plugin add https://github.com/homerours/cordova-music-controls-plugin

otherwise all buttons was not clickable

from cordova-music-controls-plugin.

BuddyLReno avatar BuddyLReno commented on June 23, 2024

Yeah, only @homerours currently has access to publish to NPM. @homerours, could you give access to publish to NPM to @ghenry22 and/or I?

from cordova-music-controls-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.