summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu <alex_y_xu@yahoo.ca>2014-01-23 09:25:19 -0500
committerAlex Xu <alex_y_xu@yahoo.ca>2014-01-23 09:25:19 -0500
commit4dc2aa175624a4d29e4c4e8d3881461df093d13f (patch)
tree91486c5ae264c278f52c9901cb27106c4d43f0f2
parent81d121665888f7e05cc3b36d8c12bc3796fa8273 (diff)
downloadhtml5ks-4dc2aa175624a4d29e4c4e8d3881461df093d13f.tar.xz
html5ks-4dc2aa175624a4d29e4c4e8d3881461df093d13f.zip
stuff
-rw-r--r--Makefile58
-rw-r--r--www/js/api.js95
2 files changed, 78 insertions, 75 deletions
diff --git a/Makefile b/Makefile
index 352cd94..4534644 100644
--- a/Makefile
+++ b/Makefile
@@ -31,19 +31,19 @@ CVIDEO := $(MP4) $(WEBM) $(VP9) $(OGV)
video: $(CVIDEO)
%.y4m: %.mkv
- $(FFMPEG) -i $< -c:a copy $@
+ $(FFMPEG) -i "$<" -c:a copy "$@"
%.mp4: %.mkv
- $(FFMPEG) -i $< -c:v libx264 -preset slower -tune animation -c:a libfdk_aac $@
+ $(FFMPEG) -i "$<" -c:v libx264 -preset slower -tune animation -c:a libfdk_aac "$@"
%.webm: %.mkv
- $(FFMPEG) -i $< -crf 10 -b:v 1M -c:a copy $@
+ $(FFMPEG) -i "$<" -crf 10 -b:v 1M -c:a copy "$@"
%.vp9.webm: %.mkv
- $(FFMPEG) -i $< -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a copy $@
+ $(FFMPEG) -i "$<" -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a libopus -vbr 1 -b:a 64k "$@"
%.ogv: %.mkv
- $(FFMPEG) -i $< -c:v libtheora -qscale:v 10 -c:a copy $@
+ $(FFMPEG) -i "$<" -c:v libtheora -qscale:v 10 -c:a copy "$@"
# === AUDIO ===
@@ -55,13 +55,13 @@ CAUDIO := $(OPUS) $(M4A)
audio: $(CAUDIO)
%.wav: %.ogg
- $(FFMPEG) -i $< -c:a pcm_s16le $@
+ $(FFMPEG) -i "$<" -c:a pcm_s16le "$@"
%.opus: %.wav
- $(FFMPEG) -i $< -c:a libopus -b:a 64k $@
+ $(FFMPEG) -i "$<" -c:a libopus -vbr 1 -b:a 64k "$@"
%.m4a: %.wav
- $(FFMPEG) -i $< -c:a libfdk_aac -vbr 1 $@
+ $(FFMPEG) -i "$<" -c:a libfdk_aac -vbr 1 "$@"
# === IMAGES ===
@@ -80,40 +80,40 @@ $(DUMP)/ui/ctc_strip.webp: $(DUMP)/ui/ctc_strip.png
:
%.webp: %.png
- $(PNGQUANT) --force --speed 1 --ext .png $<
- $(ZOPFLIPNG) -m -y $< $<
- $(DEFLOPT) $<
- $(DEFLUFF) < $< > $<.tmp
- mv -f $<.tmp $<
- $(CWEBP) -q 99 -m 6 $< -o $@
+ $(PNGQUANT) --force --speed 1 --ext .png "$<"
+ $(ZOPFLIPNG) -m -y "$<" "$<"
+ $(DEFLOPT) "$<"
+ $(DEFLUFF) < "$<" > "$<".tmp
+ mv -f "$<".tmp "$<"
+ $(CWEBP) -q 99 -m 6 "$<" -o "$@"
%.webp: %.jpg
- $(CWEBP) -q 90 -m 6 $< -o $@
+ $(CWEBP) -q 90 -m 6 "$<" -o "$@"
www/favicon.ico: $(DUMP)/ui/icon.png
- $(CONVERT) $< -resize 256x256 -transparent white $@
+ $(CONVERT) "$<" -resize 256x256 -transparent white "$@"
$(DUMP)/ui/bt-cf-unchecked.webp $(DUMP)/ui/bt-cf-checked.webp: %.webp: %.png
- $(CONVERT) -trim $< $<
- $(PNGQUANT) --force --speed 1 --ext .png $<
- $(ZOPFLIPNG) -m -y $< $<
- $(DEFLOPT) $<
- $(DEFLUFF) < $< > $<.tmp
- mv -f $<.tmp $<
- $(CWEBP) -q 99 -m 6 $< -o $@
+ $(CONVERT) -trim "$<" "$<"
+ $(PNGQUANT) --force --speed 1 --ext .png "$<"
+ $(ZOPFLIPNG) -m -y "$<" "$<"
+ $(DEFLOPT) "$<"
+ $(DEFLUFF) < "$<" > "$<".tmp
+ mv -f "$<".tmp "$<"
+ $(CWEBP) -q 99 -m 6 "$<" -o "$@"
$(DUMP)/ui/ctc_strip-0.png: $(CTC_ANIM_SRC)
- $(CONVERT) $< -crop 16x16 $(patsubst %.png,%*.png,$<)
- $(PNGQUANT) --force --speed 1 --ext .png $<
+ $(CONVERT) "$<" -crop 16x16 $(patsubst %.png,%*.png,$<)
+ $(PNGQUANT) --force --speed 1 --ext .png "$<"
$(DUMP)/ui/ctc_strip-%.png: $(CTC_ANIM_SRC) $(DUMP)/ui/ctc_strip-0.png
- @touch $@
+ @touch "$@"
$(DUMP)/ui/ctc_anim.png: $(CTC_ANIM_TMP)
- $(APNGASM) $@ $^ 3 100
+ $(APNGASM) "$@" $^ 3 100
$(DUMP)/ui/ctc_anim.webp: $(CTC_ANIM_TMP_WEBP)
- $(WEBPMUX) -frame $(subst $(SPACE), +30 -frame ,$^) +30 -loop 0 -o $@
+ $(WEBPMUX) -frame $(subst $(SPACE), +30 -frame ,$^) +30 -loop 0 -o "$@"
# === JS ===
@@ -122,7 +122,7 @@ JS := www/js/html5ks.js www/js/menu.js www/js/api.js www/js/play.js www/js/image
js: www/js/all.min.js
www/js/all.min.js: $(JS)
- $(UGLIFYJS) $^ -o $@ -p 2 -m -c
+ $(UGLIFYJS) $^ -o "$@" --source-map "$@".map --source-map-url ./all.min.js.map -p 2 -m -c
# === MISC ===
diff --git a/www/js/api.js b/www/js/api.js
index ed357de..e029413 100644
--- a/www/js/api.js
+++ b/www/js/api.js
@@ -33,6 +33,38 @@ window.html5ks.api = new (function () {
return when.resolve();
},
+ _loadMedia: function (el, src, types) {
+ var deferred = when.defer();
+ var i = 0;
+ var _nextType = function () {
+ for (; i < types.length; i++) {
+ var type = types[i];
+ if (el.canPlayType(type[0])) {
+ el.src = src + "." + type[1];
+ el.load();
+ el.play();
+ return true;
+ }
+ }
+ return false;
+ };
+
+ _nextType();
+
+ el.onerror = function (e) {
+ if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) {
+ if (!_nextType()) {
+ console.log("no audio formats supported");
+ deferred.resolve();
+ }
+ } else {
+ console.error("unknown audio error");
+ deferred.resolve();
+ }
+ };
+ return deferred.promise;
+ },
+
play: function (channel, name, ignore, fade) {
this.stop(channel);
var deferred = when.defer(),
@@ -55,19 +87,6 @@ window.html5ks.api = new (function () {
volume = html5ks.persistent.sfxVolume;
}
- 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);
if (fade) {
@@ -75,21 +94,16 @@ window.html5ks.api = new (function () {
}
deferred.resolve();
}, false);
- audio.onerror = function (e) {
- if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) {
- i = setNextType(i);
- if (!i) {
- console.log("no audio formats supported");
- deferred.resolve();
- }
- } else {
- console.error("unknown audio error");
- deferred.resolve();
- }
- };
- audio.load();
+
audio.volume = fade ? 0 : volume;
- audio.play();
+ this._loadMedia(audio, src, [
+ ['audio/ogg; codecs="opus"', "opus"],
+ ['audio/ogg; codecs="vorbis"', "ogg"],
+ ['audio/x-m4a', "m4a"],
+ ['audio/aac', "aac"],
+ ['audio/wav; codecs="1"', "wav"]]).then(function () { deferred.resolve(); });
+ // TODO: fix this garbage -------------------------------^
+
return deferred.promise;
},
@@ -115,7 +129,7 @@ window.html5ks.api = new (function () {
movie_cutscene: function (vid_src, skippable) {
var deferred = when.defer(),
video = html5ks.elements.video,
- src = "dump/video/" + vid_src + ".";
+ src = "dump/video/" + vid_src;
this.stop("all");
clearInterval(html5ks._nextTimeout);
@@ -124,23 +138,15 @@ window.html5ks.api = new (function () {
return deferred.resolve();
}
- var types = {
- "vp9": "vp9.webm",
- "webm": "webm",
- "ogg": "ogv",
- "h264": "mp4"
- };
- for (var type in types) {
- if (Modernizr.video[type]) {
- video.src = src + types[type];
- break;
- }
- }
-
- video.load();
+ this._loadMedia(video, src, [
+ ['video/webm; codecs="vp9,opus"', "vp9.webm"],
+ ['video/webm; codecs="vp8,vorbis"', "webm"],
+ ['video/ogg; codecs="theora,vorbis"', "ogv"],
+ // TODO: check that this is the right codec
+ ['video/mp4; codecs="avc1.42E01E,mp4a.40.2"']]).then(function () { deferred.resolve(); });
+ // TODO: fix this garbage
video.style.display = "block";
video.volume = html5ks.persistent.musicVolume;
- video.play();
var done = function () {
video.style.display = "none";
video.pause();
@@ -159,9 +165,6 @@ window.html5ks.api = new (function () {
}
};
video.onended = done;
- video.onerror = function () {
- deferred.reject(this.error);
- };
return deferred.promise;
},