@@ -417,10 +417,13 @@ public IAudioDataIO GetFromStream(Stream s)
417
417
s . Seek ( 0 , SeekOrigin . Begin ) ;
418
418
byte [ ] data = new byte [ 32 ] ;
419
419
long offset = 0 ;
420
+ bool hasID3v2 = false ;
420
421
if ( s . Read ( data , 0 , 32 ) < 32 ) return getFromFormat ( IN_MEMORY , new AudioFormat ( Format . UNKNOWN_FORMAT ) ) ;
421
422
// Hardcoded case of ID3v2 as it is the sole standard metadata system to appear at the beginning of file
423
+ // NB : useful to detect files tagged with ID3v2 even though their format isn't compatible (e.g. MP4/M4A)
422
424
if ( ID3v2 . IsValidHeader ( data ) )
423
425
{
426
+ hasID3v2 = true ;
424
427
byte [ ] data2 = new byte [ 4 ] ;
425
428
Array . Copy ( data , 6 , data2 , 0 , 4 ) ; // bytes 6-9 only
426
429
int id3v2Size = StreamUtils . DecodeSynchSafeInt32 ( data2 ) + 10 ; // 10 being the size of the header
@@ -433,13 +436,13 @@ public IAudioDataIO GetFromStream(Stream s)
433
436
List < AudioFormat > expensiveFormats = new List < AudioFormat > ( ) ;
434
437
foreach ( AudioFormat f in getFormats ( ) )
435
438
{
436
- if ( f . CheckHeader != null && f . CheckHeader ( data ) ) return getFromFormat ( IN_MEMORY , f ) ;
439
+ if ( f . CheckHeader != null && f . CheckHeader ( data ) ) return checkFromFormat ( IN_MEMORY , f , hasID3v2 ) ;
437
440
if ( f . SearchHeader != null ) expensiveFormats . Add ( f ) ;
438
441
}
439
442
foreach ( AudioFormat f in expensiveFormats )
440
443
{
441
444
s . Seek ( offset , SeekOrigin . Begin ) ;
442
- if ( f . SearchHeader ( s ) ) return getFromFormat ( IN_MEMORY , f ) ;
445
+ if ( f . SearchHeader ( s ) ) return checkFromFormat ( IN_MEMORY , f , hasID3v2 ) ;
443
446
}
444
447
return getFromFormat ( IN_MEMORY , new AudioFormat ( Format . UNKNOWN_FORMAT ) ) ;
445
448
}
@@ -448,6 +451,14 @@ public IAudioDataIO GetFromStream(Stream s)
448
451
s . Seek ( 0 , SeekOrigin . Begin ) ;
449
452
}
450
453
}
454
+ private static IAudioDataIO checkFromFormat ( string path , AudioFormat theFormat , bool hasID3v2 )
455
+ {
456
+ var result = getFromFormat ( path , theFormat ) ;
457
+ if ( hasID3v2 && ! result . GetSupportedMetas ( ) . Contains ( MetaDataIOFactory . TagType . ID3V2 ) )
458
+ LogDelegator . GetLogDelegate ( ) ( Log . LV_WARNING , "ATL doesn't support " + result . AudioFormat . Name + " files illegally tagged with ID3v2" ) ;
459
+ return result ;
460
+ }
461
+
451
462
452
463
private static IAudioDataIO getFromFormat ( string path , AudioFormat theFormat )
453
464
{
0 commit comments