diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2014-01-05 20:22:51 -0500 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2014-01-05 20:22:51 -0500 |
commit | 055870a6b2914949ee0aab4cd7eb5e802d9c551c (patch) | |
tree | 544f236917c355915e0e3e0e001062e681b88ea8 /www/js/api.js | |
parent | 00faee3432b8c78ce0f4c528e602f550663390e9 (diff) | |
download | html5ks-055870a6b2914949ee0aab4cd7eb5e802d9c551c.tar.xz html5ks-055870a6b2914949ee0aab4cd7eb5e802d9c551c.zip |
Add console.error to most .then, speed up Makefile
Diffstat (limited to 'www/js/api.js')
-rw-r--r-- | www/js/api.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/www/js/api.js b/www/js/api.js index 648d0f8..89ecdd3 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -51,12 +51,18 @@ window.html5ks.api = new (function () { volume = html5ks.persistent.sfxVolume; } - ["opus", "ogg", "m4a", "wav"].some(function (type) { - if (Modernizr.audio[type]) { - audio.src = src + "." + type; - return true; + var types = ["opus", "ogg", "m4a", "wav"]; + + var setNextType = function (i) { + for (; i < types.length; i++) { + if (Modernizr.audio[types[i]]) { + audio.src = src + "." + types[i]; + return i; + } } - }); + }; + + var i = setNextType(0); audio.addEventListener("playing", function playing() { audio.removeEventListener("playing", playing, false); @@ -66,8 +72,14 @@ window.html5ks.api = new (function () { deferred.resolve(); }, false); audio.onerror = function (e) { - console.error(audio.error); - deferred.resolve(); + if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) { + i = setNextType(i); + if (i) { + deferred.resolve(); + } else { + throw new Error(e); + } + } }; audio.load(); audio.volume = fade ? 0 : volume; |