do not use blob constructor if not present, and closure workaround
This commit is contained in:
Родитель
e9dfb4115d
Коммит
f88f3af217
42
emcc
42
emcc
|
@ -832,8 +832,18 @@ try:
|
|||
if DEBUG: print >> sys.stderr, 'emcc: setting up files'
|
||||
code = ''
|
||||
|
||||
code += 'var BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : console.log("warning: cannot build blobs"));\n'
|
||||
code += 'var URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : console.log("warning: cannot create object URLs");\n'
|
||||
code += '''
|
||||
var BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : console.log("warning: cannot build blobs"));
|
||||
var URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : console.log("warning: cannot create object URLs");
|
||||
var hasBlobConstructor;
|
||||
try {
|
||||
new Blob();
|
||||
hasBlobConstructor = true;
|
||||
} catch(e) {
|
||||
hasBlobConstructor = false;
|
||||
console.log("warning: no blob constructor, cannot create blobs with mimetypes");
|
||||
}
|
||||
'''
|
||||
|
||||
code += 'var preloadedImages = {}; // maps url to image data\n'
|
||||
code += 'var preloadedAudios = {}; // maps url to audio data\n'
|
||||
|
@ -929,19 +939,25 @@ try:
|
|||
img.src = url;
|
||||
''' % { 'filename': filename }
|
||||
elif audio:
|
||||
# Need actual blob constructor here, to set the mimetype or else audios fail to decode
|
||||
finish = '''
|
||||
var b = new Blob([byteArray.buffer], { type: '%(mimetype)s' });
|
||||
var url = URLObject.createObjectURL(b); // XXX we never revoke this!
|
||||
var audio = new Audio();
|
||||
audio.oncanplaythrough = function() {
|
||||
audio.oncanplaythrough = null;
|
||||
preloadedAudios['%(filename)s'] = audio;
|
||||
if (hasBlobConstructor) {
|
||||
var b = new Blob([byteArray.buffer], { type: '%(mimetype)s' });
|
||||
var url = URLObject.createObjectURL(b); // XXX we never revoke this!
|
||||
var audio = new Audio();
|
||||
audio['oncanplaythrough'] = function() { // XXX string for closure
|
||||
audio['oncanplaythrough'] = null;
|
||||
preloadedAudios['%(filename)s'] = audio;
|
||||
removeRunDependency();
|
||||
};
|
||||
audio.onerror = function(event) {
|
||||
console.log('Audio %(filename)s could not be decoded');
|
||||
};
|
||||
audio.src = url;
|
||||
} else {
|
||||
preloadedAudios['%(filename)s'] = new Audio(); // empty shim
|
||||
removeRunDependency();
|
||||
};
|
||||
audio.onerror = function(event) {
|
||||
console.log('Audio %(filename)s could not be decoded');
|
||||
};
|
||||
audio.src = url;
|
||||
}
|
||||
''' % { 'filename': filename, 'mimetype': AUDIO_MIMETYPES[suffix(filename)] }
|
||||
else:
|
||||
finish = 'removeRunDependency();\n'
|
||||
|
|
|
@ -6450,7 +6450,8 @@ f.close()
|
|||
shutil.copyfile(path_from_root('tests', 'sounds', 'alarmcreatemiltaryfoot_1.wav'), os.path.join(self.get_dir(), 'sound2.wav'))
|
||||
open(os.path.join(self.get_dir(), 'sdl_audio.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio.c')).read()))
|
||||
|
||||
Popen(['python', EMCC, os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '-o', 'page.html']).communicate()
|
||||
# use closure to check for a possible bug with closure minifying away newer Audio() attributes
|
||||
Popen(['python', EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]']).communicate()
|
||||
self.run_browser('page.html', '', '/report_result?1')
|
||||
|
||||
def test_worker(self):
|
||||
|
|
|
@ -12,7 +12,7 @@ void play() {
|
|||
int channel = Mix_PlayChannel(-1, sound, 1);
|
||||
assert(channel >= 0);
|
||||
|
||||
emscripten_run_script("setTimeout(_play2, 1000)");
|
||||
emscripten_run_script("setTimeout(Module['_play2'], 1000)");
|
||||
}
|
||||
|
||||
void play2() {
|
||||
|
@ -20,7 +20,7 @@ void play2() {
|
|||
assert(channel2 >= 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
SDL_Init(SDL_INIT_AUDIO);
|
||||
|
||||
int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
|
||||
|
@ -32,12 +32,12 @@ int main() {
|
|||
assert(sound);
|
||||
|
||||
play();
|
||||
if (ret == 12121) play2(); // keep it alive
|
||||
if (argc == 12121) play2(); // keep it alive
|
||||
|
||||
emscripten_run_script("element = document.createElement('input');"
|
||||
"element.setAttribute('type', 'button');"
|
||||
"element.setAttribute('value', 'replay!');"
|
||||
"element.setAttribute('onclick', '_play()');"
|
||||
"element.setAttribute('onclick', 'Module[\"_play\"]()');"
|
||||
"document.body.appendChild(element);");
|
||||
|
||||
printf("you should hear two sounds. press the button to replay!\n");
|
||||
|
|
Загрузка…
Ссылка в новой задаче