object urls for FUCKING WINDOZE
parent
a8c8ef507d
commit
4b479b599d
|
@ -78,10 +78,15 @@ GameLib.D3.Audio.prototype.createInstance = function() {
|
||||||
|
|
||||||
var audioLoader = new THREE.AudioLoader();
|
var audioLoader = new THREE.AudioLoader();
|
||||||
|
|
||||||
|
console.log('loading audio : ' + this.name);
|
||||||
|
|
||||||
//Load a sound and set it as the Audio object's buffer
|
//Load a sound and set it as the Audio object's buffer
|
||||||
audioLoader.load(
|
audioLoader.load(
|
||||||
this.apiUrl + this.path + '?ts=' + Date.now(),
|
this.apiUrl + this.path + '?ts=' + Date.now(),
|
||||||
function( buffer ) {
|
function( buffer ) {
|
||||||
|
|
||||||
|
console.log('loaded audio: ' + this.name);
|
||||||
|
|
||||||
this.instance.setBuffer( buffer );
|
this.instance.setBuffer( buffer );
|
||||||
this.instance.setLoop( this.loop );
|
this.instance.setLoop( this.loop );
|
||||||
this.instance.setVolume( this.volume );
|
this.instance.setVolume( this.volume );
|
||||||
|
|
|
@ -856,31 +856,60 @@ GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallb
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
|
|
||||||
var objectUrl = false;
|
window.URL = window.URL || window.webkitURL;
|
||||||
|
|
||||||
var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=';
|
console.log(image.name + ' - response type : ' + this.response.type);
|
||||||
|
|
||||||
try {
|
var url;
|
||||||
if (this.response.type !== 'application/json') {
|
|
||||||
url = window.URL.createObjectURL(this.response);
|
if (this.response.type.indexOf('application/json') !== -1) {
|
||||||
objectUrl = true;
|
|
||||||
|
var base64 = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=';
|
||||||
|
|
||||||
|
function fixBinary (bin) {
|
||||||
|
var length = bin.length;
|
||||||
|
var buf = new ArrayBuffer(length);
|
||||||
|
var arr = new Uint8Array(buf);
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
arr[i] = bin.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
if (errorCallback) {
|
var binary = fixBinary(atob(base64));
|
||||||
errorCallback({
|
var blob = new Blob([binary], {type: 'image/png'});
|
||||||
result: 'failure',
|
try {
|
||||||
message: 'invalid server response trying to download image ' + data.image.name
|
url = window.URL.createObjectURL(blob);
|
||||||
});
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (errorCallback) {
|
||||||
|
errorCallback({
|
||||||
|
result: 'failure',
|
||||||
|
message: 'invalid server response trying to download image ' + data.image.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('creating url : ' + url);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
url = window.URL.createObjectURL(this.response);
|
||||||
|
} catch (error) {
|
||||||
|
if (errorCallback) {
|
||||||
|
errorCallback({
|
||||||
|
result: 'failure',
|
||||||
|
message: 'invalid server response trying to download image ' + data.image.name
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var img = document.createElement('img');
|
var img = new Image();
|
||||||
|
|
||||||
img.onload = function () {
|
img.onload = function() {
|
||||||
|
|
||||||
if (objectUrl) {
|
window.URL.revokeObjectURL(url);
|
||||||
window.URL.revokeObjectURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(img);
|
callback(img);
|
||||||
|
@ -889,6 +918,7 @@ GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallb
|
||||||
if (onLoaded) {
|
if (onLoaded) {
|
||||||
onLoaded(image, data.createTexture);
|
onLoaded(image, data.createTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
img.src = url;
|
img.src = url;
|
||||||
|
|
Loading…
Reference in New Issue