amplitudejs icon indicating copy to clipboard operation
amplitudejs copied to clipboard

Can't initialize Amplitude with playlists only

Open Sun0fABeach opened this issue 4 years ago • 3 comments

Issue description

Amplitude doesn't properly initialize if I provide a playlist config containing all the songs, and leave out the songs array.

Environment

  • What's My Browser Support link: https://www.whatsmybrowser.org/b/3ZG9I
  • Amplitude.js Version: 5.0.3

Steps to reproduce the issue

  1. Initialize Amplitude like so. Note that the only song here is defined inside a playlist and there is no top-level songs array:
Amplitude.init({
  playlists: {
    emancipator: {
      songs: [{
        "name": "Anthem",
        "artist": "Emancipator",
        "album": "Soon It Will Be Cold Enough",
        "url": "../songs/Anthem-Emancipator.mp3",
        "cover_art_url": "../album-art/soon-it-will-be-cold-enough.jpg"
      }],
      title: 'Emancipator\'s Greatest Hits'
    }
  }
})
  1. Try to play the song by clicking on an element with class="amplitude-play-pause" data-amplitude-song-index="0" data-amplitude-playlist="emancipator"

What is expected?

The song is played.

Additional details / screenshots

I can make it work by providing a dummy element for songs like so:

Amplitude.init({
  songs: [{ url: "" }],
  playlists: {
    emancipator: {
      songs: [{
        "name": "Anthem",
        "artist": "Emancipator",
        "album": "Soon It Will Be Cold Enough",
        "url": "../songs/Anthem-Emancipator.mp3",
        "cover_art_url": "../album-art/soon-it-will-be-cold-enough.jpg"
      }],
      title: 'Emancipator\'s Greatest Hits'
    }
  }
})

Now the song can be played.

Sun0fABeach avatar Jul 03 '20 19:07 Sun0fABeach

Hey @Sun0fABeach, thanks for the detailed bug report.

Dan made a few bug fixes in v5.1.0.

Can you let us know if you are still having the issue in the latest version?

jaydrogers avatar Jul 03 '20 20:07 jaydrogers

Hi. I upgraded to v5.1.0 and the issue remains. Further observations that might help:

  • when I try to play the song by clicking on said element, I get the following console error:
amplitude.js Uncaught TypeError: Cannot set property 'active_index' of undefined
    at Object.setActivePlaylist
    at handleSongInPlaylistPlayPause
    at HTMLLIElement.handle
  • when I initialize Amplitude with debug: true, I get the following console message:
Please provide a songs object for AmplitudeJS to run!

Looks like someone explicitly decided to check for the songs property and to print that message + abort initialization when it's not there. Since it's possible to define all the songs in the playlist config, that check should be made smarter.

Sun0fABeach avatar Jul 04 '20 07:07 Sun0fABeach

After the merger and release of v5.3.0, we re-opened this and need to revisit how to initialize AmplitudeJS without a playlist. This was fixed in v5.2., but due to a host of other issues, we had to rebase and move forward. I'll explore options to make sure this works without issue.

danpastori avatar Feb 16 '21 17:02 danpastori