AmplitudeJS "start_song" issues

Hi @jaydrogers, Hi @danpastori

I use v5.3.1 and my problem if with start_song parameter itself. My problem is most related with the original github issue than this topic.

Quick exemple:

             let init_conf = {
                "continue_next": false,
                "preload": "metadata",
                "songs": finalPlaylist,
                "start_song": 1,
                "callbacks": {
                    "initialized": function() {
                       ...
                    },
                    "ended": () => {
                        let nextEpisode = document.querySelector("[data-index='"+(Amplitude.getActiveIndex() + 1) +"']");
                        if (nextEpisode != null) {
                            let url = nextEpisode.querySelector('a.play').href;
                            if (url != null) {
                                window.open(url, '_self');
                            }
                        }
                    }
                }
            };
            Amplitude.init(init_conf);

As you can see with “ended” event, i want to load a specific url for each song (SEO…), so if i a am on the 2nd audio page, i want to set player on the 2nd media (index 1).

finalPlaylist is an array of 4 songs, but, even with “start_song”: 1, it will play song index 0 on each page.

The reason is the condition in amplitude.js: amplitudejs/amplitude.js at 745583f1361a93fce1cd298d7fc86915cc1f20ac · serversideup/amplitudejs · GitHub

without the starting_playlist parameter, start_song has no effect, while starting_playlist is useless here. If i use a custom amplitude.js without the starting_playlist test, start_song works as espected.

For moment, the workaround is to call Amplitude.playSongAtIndex(1) in initialized callback, but it’s not a good solution:

  1. When player is displayed, i see the first song metatada, then, few seconds later, the player display the right metadata, this is not a good user experience.
  2. playSongAtIndex trigger song_change event, and this is irrelevent in this use case

Thanks :slight_smile:

Thanks @ErnadoO for the heads up! You were right, the start_song required a starting_playlist. I probably missed a ! in there because we actually don’t want a starting_playlist when checking the start_song.

I pushed the fix and the new version is 5.3.2: Release v5.3.2 · serversideup/amplitudejs · GitHub.

Let me know how that works for you!

Hi @danpastori

It works like a charm; thanks ! :slight_smile:

1 Like

Awesome! Glad it worked!