amplitudejs icon indicating copy to clipboard operation
amplitudejs copied to clipboard

Amplitude callbacks are not triggered at all

Open maurotbf opened this issue 5 years ago • 2 comments

Hi and thanks for this wonderful library! I've been through many examples and I can't get callbacks parameters to work, this is my code (songs array is empty because it's being filled by adding audios to the main player). All functionalities are working perfectly but I need this callback to set my playlist status when the song ends. It doesn't work with Prev and next as well

Amplitude.init( songs:[], callbacks: { song_change: function(){ alert('here'); } } );

UPDATE: no configurations working from me at all. I tried playback speed at 2.0 and speed is 1.0. I pulled Amplitude configs and all seem to be the default ones.

Thanks in advance! v5.2.0 via jsdeliver

maurotbf avatar Aug 06 '20 04:08 maurotbf

Hi @maurotbf ,

Thanks for sending over the information. There's a known bug I'm in the process of fixing involving an empty songs array and callbacks/config not working as expected. If you were to pre-fill your songs array with one song, do you have the same issue? Also, are there any console errors?

I'll try to take a look within the next couple days.

danpastori avatar Aug 06 '20 04:08 danpastori

Hi @danpastori thank you for the response! I ended making this working by:

(1) placing the Amplitude.init outside my $(document).ready wrapper (2) creating an empty mp3 to work as placeholder and helping preserve the config parameters (once this has been started, I remove the placeholder with Amplitude.removeSong(0)), something like this:

Amplitude.init({ songs: [ { 'name': '', 'url': '../audio/placeholder.mp3' }, ], callbacks: { next: function() { }, pause: function() { $('.amplitude-play-pause').removeClass('c-player__pause'); }, play: function() { // Patch for range converted to number field (?) $(document).find('.amplitude-song-slider').attr('type', 'range'); $('.amplitude-play-pause').addClass('c-player__pause'); let playlistItems = $(document).find('.c-playlist__item'); $(document).find('.now-playing').removeClass('now-playing'); if (playlistItems.length) { playlistItems.eq(Amplitude.getActiveIndex()).addClass('now-playing'); } }, playlist_changed: function() { console.log('playlist changed to '+Amplitude.getSongs().length+' items'); } }, playback_speed: 1.0, });

And this is all.

Thank you very much and stay safe!

maurotbf avatar Aug 07 '20 19:08 maurotbf