@@ -28,6 +28,7 @@ func TestNewAudioFromBytes(t *testing.T) {
2828 {"Valid AAC audio" , "small_sample.aac" , "audio/aac" , 1.0 },
2929 {"Valid FLAC audio" , "small_sample.flac" , "audio/flac" , 1.0 },
3030 {"Valid M4A audio" , "small_sample.m4a" , "audio/mp4" , 1.0 },
31+ {"Valid M4A audio (non-standard MIME)" , "small_sample.m4a" , "audio/x-m4a" , 1.0 },
3132 {"Valid WMA audio" , "small_sample.wma" , "audio/x-ms-wma" , 1.0 },
3233 {"Valid AIFF audio" , "small_sample.aiff" , "audio/aiff" , 1.0 },
3334 {"Invalid file type" , "sample_640_426.png" , "" , 0.0 },
@@ -104,6 +105,7 @@ func TestAudioProperties(t *testing.T) {
104105 {"AAC audio" , "small_sample.aac" , "audio/aac" , 1.0 },
105106 {"FLAC audio" , "small_sample.flac" , "audio/flac" , 1.0 },
106107 {"M4A audio" , "small_sample.m4a" , "audio/mp4" , 1.0 },
108+ {"M4A audio (non-standard MIME)" , "small_sample.m4a" , "audio/x-m4a" , 1.0 },
107109 {"WMA audio" , "small_sample.wma" , "audio/x-ms-wma" , 1.0 },
108110 {"AIFF audio" , "small_sample.aiff" , "audio/aiff" , 1.0 },
109111 }
@@ -191,6 +193,7 @@ func TestNewAudioFromBytesUnified(t *testing.T) {
191193 {"AAC as unified" , "small_sample.aac" , "audio/aac" , 1.0 },
192194 {"FLAC as unified" , "small_sample.flac" , "audio/flac" , 1.0 },
193195 {"M4A as unified" , "small_sample.m4a" , "audio/mp4" , 1.0 },
196+ {"M4A as unified (non-standard MIME)" , "small_sample.m4a" , "audio/x-m4a" , 1.0 },
194197 {"WMA as unified" , "small_sample.wma" , "audio/x-ms-wma" , 1.0 },
195198 {"AIFF as unified" , "small_sample.aiff" , "audio/aiff" , 1.0 },
196199 }
@@ -206,10 +209,15 @@ func TestNewAudioFromBytesUnified(t *testing.T) {
206209 c .Assert (audio .ContentType ().String (), qt .Equals , "audio/ogg" )
207210 c .Assert (audio .Duration ().Float64 (), qt .CmpEquals (cmpopts .EquateApprox (0 , 0.1 )), tc .duration )
208211
209- // Test as non-unified (should preserve original format)
212+ // Test as non-unified (should preserve original format, but normalized )
210213 audioOriginal , err := NewAudioFromBytes (audioBytes , tc .contentType , tc .filename , false )
211214 c .Assert (err , qt .IsNil )
212- c .Assert (audioOriginal .ContentType ().String (), qt .Equals , tc .contentType )
215+ expectedContentType := tc .contentType
216+ // Handle MIME type normalization for non-standard types
217+ if tc .contentType == "audio/x-m4a" {
218+ expectedContentType = "audio/mp4"
219+ }
220+ c .Assert (audioOriginal .ContentType ().String (), qt .Equals , expectedContentType )
213221 c .Assert (audioOriginal .Duration ().Float64 (), qt .CmpEquals (cmpopts .EquateApprox (0 , 0.1 )), tc .duration )
214222 })
215223 }
@@ -306,3 +314,54 @@ func TestAllSupportedAudioFormats(t *testing.T) {
306314 })
307315 }
308316}
317+
318+ func TestAudioMIMETypeNormalization (t * testing.T ) {
319+ t .Parallel ()
320+ c := qt .New (t )
321+
322+ // Test that audio/x-m4a is properly normalized to audio/mp4
323+ c .Run ("audio/x-m4a normalization" , func (c * qt.C ) {
324+ audioBytes , err := os .ReadFile ("testdata/small_sample.m4a" )
325+ c .Assert (err , qt .IsNil )
326+
327+ // Create audio with non-standard MIME type
328+ audioXM4A , err := NewAudioFromBytes (audioBytes , "audio/x-m4a" , "test.m4a" , false )
329+ c .Assert (err , qt .IsNil )
330+
331+ // Create audio with standard MIME type
332+ audioMP4 , err := NewAudioFromBytes (audioBytes , "audio/mp4" , "test.m4a" , false )
333+ c .Assert (err , qt .IsNil )
334+
335+ // Both should have the same normalized content type
336+ c .Assert (audioXM4A .ContentType ().String (), qt .Equals , "audio/mp4" )
337+ c .Assert (audioMP4 .ContentType ().String (), qt .Equals , "audio/mp4" )
338+ c .Assert (audioXM4A .ContentType ().String (), qt .Equals , audioMP4 .ContentType ().String ())
339+
340+ // Both should have the same duration and properties
341+ c .Assert (audioXM4A .Duration ().Float64 (), qt .CmpEquals (cmpopts .EquateApprox (0 , 0.1 )), audioMP4 .Duration ().Float64 ())
342+ c .Assert (audioXM4A .SampleRate ().Integer (), qt .Equals , audioMP4 .SampleRate ().Integer ())
343+ })
344+
345+ // Test that audio/mp3 is properly normalized to audio/mpeg
346+ c .Run ("audio/mp3 normalization" , func (c * qt.C ) {
347+ audioBytes , err := os .ReadFile ("testdata/small_sample.mp3" )
348+ c .Assert (err , qt .IsNil )
349+
350+ // Create audio with non-standard MIME type
351+ audioMP3 , err := NewAudioFromBytes (audioBytes , "audio/mp3" , "test.mp3" , false )
352+ c .Assert (err , qt .IsNil )
353+
354+ // Create audio with standard MIME type
355+ audioMPEG , err := NewAudioFromBytes (audioBytes , "audio/mpeg" , "test.mp3" , false )
356+ c .Assert (err , qt .IsNil )
357+
358+ // Both should have the same normalized content type
359+ c .Assert (audioMP3 .ContentType ().String (), qt .Equals , "audio/mpeg" )
360+ c .Assert (audioMPEG .ContentType ().String (), qt .Equals , "audio/mpeg" )
361+ c .Assert (audioMP3 .ContentType ().String (), qt .Equals , audioMPEG .ContentType ().String ())
362+
363+ // Both should have the same duration and properties
364+ c .Assert (audioMP3 .Duration ().Float64 (), qt .CmpEquals (cmpopts .EquateApprox (0 , 0.1 )), audioMPEG .Duration ().Float64 ())
365+ c .Assert (audioMP3 .SampleRate ().Integer (), qt .Equals , audioMPEG .SampleRate ().Integer ())
366+ })
367+ }
0 commit comments