amplitudejs
amplitudejs copied to clipboard
Add getNextSong() to API
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
https://github.com/serversideup/amplitudejs/blob/65a072dace2d4a56e65fb78d57afc8d4f37465d6/src/utilities/audioNavigation.js#L100-L151
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