@@ -207,17 +207,19 @@ static int MusicHTML5_Open(const SDL_AudioSpec *spec)
207
207
{ type : "audio/ogg" , magic : [0x4f , 0x67 , 0x67 , 0x53 ] }, // OggS
208
208
{ type : "audio/flac" , magic : [0x66 , 0x4c , 0x61 , 0x43 ] }, // fLaC
209
209
//{ type: "audio/midi", magic: [0x4d, 0x54, 0x68, 0x64] }, // MThd
210
- { type : "audio/mp3 " , magic : [0x49 , 0x44 , 0x33 ] }, // ID3
210
+ { type : "audio/mpeg " , magic : [0x49 , 0x44 , 0x33 ] }, // ID3
211
211
{ type : "audio/wav" , magic : [0x52 , 0x49 , 0x46 , 0x46 ] },
212
- { type : "audio/mp4" , magic : [0x00 , 0x00 , 0x00 , 0x20 , 0x66 , 0x74 , 0x79 , 0x70 , 0x69 , 0x73 , 0x6F , 0x6D ] },
212
+ { type : "audio/mp4" , offset : 4 , magic : [0x66 , 0x74 , 0x79 , 0x70 , 0x69 , 0x73 , 0x6F , 0x6D ] },
213
+ { type : "audio/mp4" , offset : 4 , magic : [0x66 , 0x74 , 0x79 , 0x70 , 0x4D , 0x34 , 0x41 , 0x20 ] },
213
214
{ type : "audio/x-aiff" , magic : [0x46 , 0x4F , 0x52 , 0x4D ] },
214
215
{ type : ["audio/webm" , "audio/x-matroska" ], magic : [0x1A , 0x45 , 0xDF , 0xA3 ] }
215
216
];
216
217
217
218
targets .some ((target ) = > {
218
219
const targetMagic = target .magic ;
219
220
const magicLength = targetMagic .length ;
220
- const magic = buf .slice (0 , magicLength );
221
+ const offset = target .offset || 0 ;
222
+ const magic = buf .slice (offset , offset + magicLength );
221
223
222
224
let matching = true;
223
225
for (let i = 0 ; i < magicLength ; i ++ ) {
@@ -239,8 +241,11 @@ static int MusicHTML5_Open(const SDL_AudioSpec *spec)
239
241
});
240
242
241
243
// MP3 special case
242
- if (!canPlay && magic [0 ] == = 0xFF && (magic [1 ] & 0xFE ) == = 0xFA )
243
- canPlay = Module ["SDL2Mixer" ].canPlayType ("audio/mp3" );
244
+ if (!canPlay ) {
245
+ const magic = buf .slice (0 , 2 );
246
+ if (magic [0 ] == = 0xFF && (magic [1 ] & 0xFE ) == = 0xFA )
247
+ canPlay = Module ["SDL2Mixer" ].canPlayType ("audio/mp3" );
248
+ }
244
249
245
250
return canPlay ;
246
251
},
@@ -334,21 +339,23 @@ static void *MusicHTML5_CreateFromRW(SDL_RWops *src, int freesrc)
334
339
335
340
if (buf && size > 0 )
336
341
{
342
+ SDL_bool force = (SDL_GetHint ("SDL_MIXER_HTML5_DISABLE_TYPE_CHECK" ) != NULL );
337
343
id = EM_ASM_INT ({
338
344
const ptr = $0 ;
339
345
const size = $1 ;
340
346
const context = $2 ;
347
+ const force = $3 ;
341
348
342
349
const buf = new Uint8Array (Module .HEAPU8 .buffer , ptr , size );
343
350
344
- if (!Module ["SDL2Mixer" ].canPlayMagic (buf ))
351
+ if (!force && ! Module ["SDL2Mixer" ].canPlayMagic (buf ))
345
352
return -1 ;
346
353
347
354
const url = Module ["SDL2Mixer" ].createBlob (buf );
348
355
const id = Module ["SDL2Mixer" ].createMusic (url , context );
349
356
350
357
return id ;
351
- }, buf , size , music );
358
+ }, buf , size , music , force );
352
359
}
353
360
354
361
if (id == -1 )
@@ -376,6 +383,7 @@ static void *MusicHTML5_CreateFromFile(const char *file)
376
383
{
377
384
MusicHTML5 * music = (MusicHTML5 * )SDL_calloc (1 , sizeof * music );;
378
385
int id = -1 ;
386
+ SDL_bool force = (SDL_GetHint ("SDL_MIXER_HTML5_DISABLE_TYPE_CHECK" ) != NULL );
379
387
380
388
if (music == NULL ) {
381
389
Mix_SetError ("Out of memory" );
@@ -385,14 +393,15 @@ static void *MusicHTML5_CreateFromFile(const char *file)
385
393
id = EM_ASM_INT ({
386
394
const file = UTF8ToString ($0 );
387
395
const context = $1 ;
396
+ const force = $2 ;
388
397
389
398
let url ;
390
399
try {
391
400
// Is path in FS?
392
401
const buf = FS .readFile (file );
393
402
url = Module ["SDL2Mixer" ].createBlob (buf );
394
403
395
- let canPlay = Module ["SDL2Mixer" ].canPlayFile (file );
404
+ let canPlay = force || Module ["SDL2Mixer" ].canPlayFile (file );
396
405
397
406
if (!canPlay )
398
407
canPlay = Module ["SDL2Mixer" ].canPlayMagic (buf );
@@ -405,13 +414,13 @@ static void *MusicHTML5_CreateFromFile(const char *file)
405
414
url = file ;
406
415
407
416
// Check audio capability by file extension
408
- if (!Module ["SDL2Mixer" ].canPlayFile (url ))
417
+ if (!force && ! Module ["SDL2Mixer" ].canPlayFile (url ))
409
418
return -1 ;
410
419
}
411
420
412
421
const id = Module ["SDL2Mixer" ].createMusic (url , context );
413
422
return id ;
414
- }, file , music );
423
+ }, file , music , force );
415
424
416
425
if (id == -1 ) {
417
426
SDL_free (music );
0 commit comments