Browse Source

try to fix snd

wayou 9 years ago
parent
commit
c938e894ec
2 changed files with 25 additions and 8 deletions
  1. 0 0
      src/trex/index.html
  2. 25 8
      src/trex/scripts/runner.js

+ 0 - 0
src/trex/iindex.html → src/trex/index.html


+ 25 - 8
src/trex/scripts/runner.js

@@ -256,13 +256,30 @@
                 document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
 
             for (var sound in Runner.sounds) {
-                var soundSrc = resourceTemplate.getElementById(Runner.sounds[sound]).src;
-                soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
-                var buffer = decodeBase64ToArrayBuffer(soundSrc);
-                // Async, so no guarantee of order in array.
-                this.audioContext.decodeAudioData(buffer, function(index, audioData) {
-                    this.soundFx[index] = audioData;
-                }.bind(this, sound));
+                // var soundSrc = resourceTemplate.getElementById(Runner.sounds[sound]).src;
+                // soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
+
+                // var buffer = decodeBase64ToArrayBuffer(soundSrc);
+                // // Async, so no guarantee of order in array.
+                // this.audioContext.decodeAudioData(buffer, function(index, audioData) {
+                //     this.soundFx[index] = audioData;
+                // }.bind(this, sound));
+
+                var soundSrc = resourceTemplate.getElementById(Runner.sounds[sound]).getAttribute("src");
+                var request = new XMLHttpRequest();
+                request.open('GET', soundSrc, true);
+                request.responseType = 'arraybuffer';
+
+                // Decode asynchronously
+                request.onload = function() {
+                    this.audioContext.decodeAudioData(request.response, function(index, audioData) {
+                        this.soundFx[index] = audioData;
+                    }.bind(this, sound), function(err) {
+                        console.log('err loading sound:' + sound);
+                    });
+                };
+                request.send();
+
             }
         },
         /**
@@ -2004,4 +2021,4 @@
     };
 })();
 
-new Runner('.interstitial-wrapper');
+new Runner('.interstitial-wrapper');