Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getNextSong() to API #537

Open
lebanggit opened this issue Sep 28, 2024 · 0 comments
Open

Add getNextSong() to API #537

lebanggit opened this issue Sep 28, 2024 · 0 comments
Labels
Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated.

Comments

@lebanggit
Copy link

lebanggit commented Sep 28, 2024

Issue Description

Sometimes I want o know next song that i can pre/background-processing.

ex: Preload media file for smooth playing.

Expected Behavior

Add to public API

Steps To Reproduce

I saw this code to get it

if (config.repeat_song) {
/*
If the playlist is shuffled, get the now playing index.
*/
if (config.shuffle_on) {
nextIndex = config.shuffle_list[config.active_index].index;
nextSong = config.shuffle_list[nextIndex];
} else {
nextIndex = config.active_index;
nextSong = config.songs[nextIndex];
}
} else {
/*
If the shuffle is on, we use the shuffled list of
songs to determine our next song.
*/
if (config.shuffle_on) {
/*
If the active shuffle index + 1 is less than the length, then
we use the next shuffle otherwise we go to the beginning
of the shuffle list.
*/
if (parseInt(config.active_index) + 1 < config.shuffle_list.length) {
/*
Set the next index to be the index of the song in the shuffle list.
*/
nextIndex = parseInt(config.active_index) + 1;
} else {
nextIndex = 0;
endOfList = true;
}
nextSong = config.shuffle_list[nextIndex];
} else {
/*
If the active index + 1 is less than the length of the songs, then
we use the next song otherwise we go to the beginning of the
song list.
*/
if (parseInt(config.active_index) + 1 < config.songs.length) {
nextIndex = parseInt(config.active_index) + 1;
} else {
nextIndex = 0;
endOfList = true;
}
/*
Sets the next index.
*/
nextSong = config.songs[nextIndex];
}
}

And mannual function my our:

function getNextSong() {
    if(typeof Amplitude == 'undefined') return;
    let config = Amplitude.getConfig();
    if (config.repeat_song) {
      /*
        If the playlist is shuffled, get the now playing index.
      */
      if (config.shuffle_on) {
        nextIndex = config.shuffle_list[config.active_index].index;
        nextSong = config.shuffle_list[nextIndex];
      } else {
        nextIndex = config.active_index;
        nextSong = config.songs[nextIndex];
      }
    } else {
      /*
        If the shuffle is on, we use the shuffled list of
        songs to determine our next song.
      */
      if (config.shuffle_on) {
        /*
          If the active shuffle index + 1 is less than the length, then
          we use the next shuffle otherwise we go to the beginning
          of the shuffle list.
        */
        if (parseInt(config.active_index) + 1 < config.shuffle_list.length) {
          /*
            Set the next index to be the index of the song in the shuffle list.
          */
          nextIndex = parseInt(config.active_index) + 1;
        } else {
          nextIndex = 0;
          endOfList = true;
        }

        nextSong = config.shuffle_list[nextIndex];
      } else {
        /*
          If the active index + 1 is less than the length of the songs, then
          we use the next song otherwise we go to the beginning of the
          song list.
        */
        if (parseInt(config.active_index) + 1 < config.songs.length) {
          nextIndex = parseInt(config.active_index) + 1;
        } else {
          nextIndex = 0;
          endOfList = true;
        }

        /*
          Sets the next index.
        */
        nextSong = config.songs[nextIndex];
      }
    }
    
    return nextSong;
}

AmplitudeJS Version

5.3.2

Browser Information

No response

Link To Where Your Issue Can Be Reproduced

No response

Anything else?

No response

@lebanggit lebanggit added the Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated. label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated.
Projects
None yet
Development

No branches or pull requests

1 participant