AVAudioFile fails to read some files with wrong extension

Hello,

Here is an issue I encountered recently. Does anybody have feedback on this?

Issue encountered

  • AVAudioFile
    • throws when opening WAV files and MPEG-DASH files with .mp3 extension,
    • works fine with many other tested combinations of formats and extension (for example, an AIFF file with .mp3 extension is read by AVAudioFile without error).
  • The Music app, AVAudioFile and ExtAudioFile all fail on the same files.
  • However, previewing an audio file in Finder (select the file and hit the space bar) works regardless of the file extension.

Why do I consider this an issue?

  • AVAudioFile seems to rely on extension sometimes but not always to guess the audio format of the file, which leads to unexpected errors.
  • I would expect AVAudioFile to deal properly with wrong extensions for all supported audio formats.
  • ⚠️ This behaviour can cause real trouble in iOS and macOS applications using audio files coming from the user, which often have unreliable extensions.

I published some code to easily reproduce the issue:
https://github.com/ThomasHezard/AVAudioFileFormatIssue

Thank you everybody, have a great day 😎

AVAudioFile fails to read some files with wrong extension
 
 
Q