Skip to content

Commit

Permalink
Quick hack to get XHR working again under modern browsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasc committed Mar 30, 2014
1 parent 33409ef commit 255a6e7
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions Demo/route9.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,41 +152,51 @@
var clip = $("#clip").val();
var mode = $("#mode").val();
var xhr = new XMLHttpRequest();
xhr.open("GET", clip, false);
xhr.async = true;
xhr.open("GET", clip, true);
xhr.responseType = "arraybuffer";
xhr.send(null);
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
var array = Array.prototype.slice.apply(byteArray);
Module.FS.createDataFile('/', 'video.webm', array, true, false);
} else {
alert('load fail :(');
}
document.getElementById('downloadProgress').innerHTML = "Download Complete, Playing ...";
xhr.onreadystatechange = function(event) {
if (xhr.readyState != 4) {
return;
}
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
var array = Array.prototype.slice.apply(byteArray);
Module.FS.ignorePermissions = true;
Module.FS.createDataFile('/', 'video.webm', array, true, false);
} else {
alert('load fail :(');
}
document.getElementById('downloadProgress').innerHTML = "Download Complete, Playing ...";

// Pass canvas and context to the generated code, and do the actual run() here
Module.canvas = document.getElementById('canvas');
// Pass canvas and context to the generated code, and do the actual run() here
Module.canvas = document.getElementById('canvas');

if (mode == "none") {
_paint = function() {
};
_SDL_LockSurface = function() {
}
} else if (mode == "webgl") {
_paint = paint;
_SDL_LockSurface = function() {};
_SDL_Quit = function() {};
} else {
Module.ctx2D = Module.canvas.getContext('2d');
if (!Module.ctx2D) {
alert('Canvas not available :(');
return;
if (mode == "none") {
_paint = function() {
};
_SDL_LockSurface = function() {
}
} else if (mode == "webgl") {
_paint = paint;
_SDL_LockSurface = function() {};
_SDL_Quit = function() {};
} else {
Module.ctx2D = Module.canvas.getContext('2d');
if (!Module.ctx2D) {
alert('Canvas not available :(');
return;
}
}
}

console.info("Running: " + clip);
Module.run(['video.webm']);
console.info("Running: " + clip);
Module.run(['video.webm']);

play();
};

xhr.send(null);
}

var loaded = false;
Expand All @@ -197,9 +207,7 @@
if (!loaded) {
load();
loaded = true;
}

if (playing == false) {
} else if (playing == false) {
$('#play').children().first().html("Pause");
playing = true;
Module.play();
Expand Down

0 comments on commit 255a6e7

Please sign in to comment.