Amplitude callbacks are not triggered at all
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
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.
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!