JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script>
JavaScript
console.clear();
Crafty.init(200, 200);
//The Jukebox Routine
var trackCounter = 1
var nextTrack = function()
{
if (trackCounter == 4){trackCounter = 1} //if we hit the last track, reset to the first
var themeToPlay = "theme"+trackCounter
//play once
Crafty.audio.play(themeToPlay, 1);
trackCounter += 1;
}
//add the theme songs to the music quene, add event listener
Crafty.audio.add("theme1", [ "http://www.garrickcampsey.com/media/oldTexasTheme.ogg" ]);
Crafty.audio.sounds.theme1.obj.addEventListener("ended", function(){ nextTrack(); },true);
//2
Crafty.audio.add("theme2", [ "http://www.garrickcampsey.com/media/dubDrone.ogg" ]);
Crafty.audio.sounds.theme2.obj.addEventListener("ended", function(){ nextTrack(); },true);
//3
Crafty.audio.add("theme3", [ "http://www.garrickcampsey.com/media/nothingSpecial.ogg" ]);
Crafty.audio.sounds.theme3.obj.addEventListener("ended", function(){ nextTrack(); },true);
//Play the songs
nextTrack();