I have encountered an issue with my Audio Player. I created it in the document ready and set a variable for playing to false. However, even though the function seems to be called correctly, it does not set that variable to true as expected. The code for this function is triggered by a click listener.
var cartSongPlayer = new Audio();
var playingStatus = false;
var playingTrack;
function switchTrack(trackID, trackSource) {
//logging basic information:
console.log('Current Track ID ' + trackID)
console.log('Current Track Source ' + trackSource)
console.log('Previous Track ID ' + playingTrack)
console.log('Playing Status ' + playingStatus)
if (playingStatus) {
console.log('song is playing')
if (trackID == playingTrack) {
playingStatus = false;
console.log('pausing current song')
cartSongPlayer.pause();
} else {
console.log('moved to new song')
playingStatus = true;
playingTrack = trackID
cartSongPlayer.src = trackSource;
cartSongPlayer.play();
}
//no song is playing
} else {
console.log('song is not playing')
if (trackID == playingTrack) {
playingStatus = true;
console.log('resumed song')
cartSongPlayer.play();
} else {
console.log('started new song')
playingStatus = true;
playingTrack = trackID
cartSongPlayer.src = trackSource;
cartSongPlayer.play();
}
}
}