diff --git a/src/js/assets.js b/src/js/assets.js
index 85c3cad..266fba4 100644
--- a/src/js/assets.js
+++ b/src/js/assets.js
@@ -44,6 +44,8 @@ var assets = {
fonts: new Array(
'Kozuka',
'TnT'
- )
+ ),
+
+ sounds: {}
};
\ No newline at end of file
diff --git a/src/js/loader.js b/src/js/loader.js
index 4b2ed13..82c6f87 100644
--- a/src/js/loader.js
+++ b/src/js/loader.js
@@ -24,11 +24,13 @@ function Loader(){
assets.audio.forEach(function(name){
var id = name.substr(0, name.length-4);
- var audio = $("");
- audio.appendTo("#assets");
- audio.on('canplay', function(){
+ var audio = new Audio();
+ audio.src = '/assets/audio/'+name;
+ audio.load();
+ audio.onloadeddata = function(){
+ assets.sounds[id] = audio;
_this.assetLoaded();
- });
+ };
});
$.ajax({
diff --git a/src/js/loadsong.js b/src/js/loadsong.js
index 14f1f25..782660d 100644
--- a/src/js/loadsong.js
+++ b/src/js/loadsong.js
@@ -10,19 +10,23 @@ function loadSong(selectedSong){
this.run = function(){
- document.getElementById("start").play();
- $("#assets").append("");
+ //assets.sounds["start"]["audio"][0].play();
$("#assets").append("");
+ var audio = new Audio();
+ audio.src = '/songs/'+_selectedSong.folder+'/'+_selectedSong.title+'.mp3';
+ audio.load();
+
$("#music-bg").load(function(){
_bgLoaded=true;
_this.checkIfEverythingLoaded();
});
- $("#main-music").on('canplay', function(){
+ audio.onloadeddata = function(){
_musicLoaded=true;
+ assets.sounds["main-music"]=audio;
_this.checkIfEverythingLoaded();
- });
+ };
$.ajax({
url : _songFilePath,
diff --git a/src/js/songselect.js b/src/js/songselect.js
index bbe20e1..e52b772 100644
--- a/src/js/songselect.js
+++ b/src/js/songselect.js
@@ -38,7 +38,7 @@ function SongSelect(){
});
$(".song:not(.opened)").click(function(){
- document.getElementById("don").play();
+ //assets.sounds["ka"][0].play();
$(".difficulty").hide();
$(".opened").removeClass("opened", 300);
$(this).addClass("opened", 300, "linear", function(){
@@ -61,9 +61,9 @@ function SongSelect(){
songDifficulties.sort(function(a, b){
if(a.difficulty < b.difficulty)
- return -1;
- if(a.difficulty > b.difficulty)
return 1;
+ if(a.difficulty > b.difficulty)
+ return -1;
return 0;
});
diff --git a/src/js/soundsystem.js b/src/js/soundsystem.js
index 4095f58..7b7e35d 100644
--- a/src/js/soundsystem.js
+++ b/src/js/soundsystem.js
@@ -5,59 +5,43 @@ function soundSystem(controller){
var _circles = [];
var _circleID = -1;
var _measures = [];
- var _channel_max = 10;// number of channels
- var _mainMusicChannel=-1;
-
- var _audiochannels = new Array();
+ var _sounds = assets.sounds;
+ var _channels=[];
+ var _channelMAX=20;
- for (var a=0;a<_channel_max;a++) {// prepare the channels
- _audiochannels[a] = new Array();
- _audiochannels[a]['channel'] = new Audio(); // create a new audio object
- _audiochannels[a]['finished'] = -1; // expected end time for this channel
+ for (var i=0;i<_channelMAX;i++) {// prepare the channels
+ _channels[i] = {};
+ _channels[i]["end"] = -1;
+ _channels[i]["audio"] = new Audio();
}
-
- this.playSound = function(soundID){
-
- if(soundID=="main-music" && _mainMusicChannel!=-1 && _mainMusicChannel.currentTime>0 ){//if music was paused but is going to be played
- _mainMusicChannel.play();
- }
- else{
-
- for(var i=0;i<_audiochannels.length;i++){
-
- var thistime = new Date();
- if (_audiochannels[i]['finished'] < thistime.getTime()) {// is this channel finished?
- _audiochannels[i]['finished'] = thistime.getTime() + document.getElementById(soundID).duration*1000;
- _audiochannels[i]['channel'].src = document.getElementById(soundID).src;
- _audiochannels[i]['channel'].load();
- _audiochannels[i]['channel'].play();
-
- if(soundID=="main-music" && _mainMusicChannel==-1){
- _mainMusicChannel=_audiochannels[i]['channel'];
- }
- break;
- }
-
- }
- }
- }
- this.pauseSound = function(soundID, stop){
- for (var i=0;i<_audiochannels.length;i++){
- if(_audiochannels[i]['channel'].src == document.getElementById(soundID).src){
- _audiochannels[i]['channel'].pause();
- if(stop) _audiochannels[i]['channel'].currentTime=0;
- }
- }
- }
+ this.playSound = function(soundID){
+
+ for(var i=0;i<_channelMAX;i++){ //play in different sounds in different channels
+ var now = new Date();
+ if (_channels[i]["end"] < now.getTime()) {// is this channel finished?
+ _channels[i]["end"] = now.getTime() + _sounds[soundID].duration*1000;
+ _channels[i]["audio"].src = _sounds[soundID].src;
+ _channels[i]["audio"].load();
+ _channels[i]["audio"].play();
+ break;
+ }
+ }
+
+ }
+
+ this.pauseSound = function(soundID, stop){
+ _sounds[soundID].pause();
+ if(stop) _sounds[soundID].currentTime=0;
+ }
this.fadeOutMusic = function(){
- if(_mainMusicChannel.volume.toFixed(1)!=0.0){
- _mainMusicChannel.volume-=0.1;
+ if(_sounds["main-music"].volume.toFixed(1)!=0.0){
+ _sounds["main-music"].volume-=0.1;
}
else{
- _mainMusicChannel.pause();
+ _sounds["main-music"].pause();
controller.fadeOutOver();
}
}
diff --git a/src/js/titlescreen.js b/src/js/titlescreen.js
index a5f4d9b..2da5611 100644
--- a/src/js/titlescreen.js
+++ b/src/js/titlescreen.js
@@ -35,7 +35,7 @@ function Titlescreen(){
}
this.goNext = function(){
- document.getElementById("don").play();
+ //assets.sounds["don"][0].play();
new SongSelect();
}