iOS and decoding MP3/AAC data from memory buffer

Forgive me, I very new at iOS – and programming at this scale in general.

I have been digging through iOS documentation, I know there are some functions like ExtAudiofile… for decoding MP3/AAC files, but are there any that will operate on Mp3/aac data that’s already in memory?

  • WatchKit UIPageControl Dot Colour
  • Code signing Error: Application failed codesign verification
  • realm cocoa: is it possible to do queries on links
  • Get binary data from UIImage
  • warning: -Wuninitialized is not supported without -O
  • Cordova / Phonegap: Live update codebase
  • I will probably have to extract the media data (byte by byte; iOS does allow that right?) from inside another file, so I can’t just give it the URL.

    Edit: the mp3 data will be in a non-standard file format, Apple provided function should not be able to read them. I heard iOS has a hardware decoder that works on one audio stream and the OS will fallback to software decoding if there are multiple streams.

    I would rather use what Apple provides then integrate a MP3 decoder into the app.

    Solutions Collect From Internet About “iOS and decoding MP3/AAC data from memory buffer”

    You can use ExtAudioFileRead to read a file that is in memory, but you have to use AudioFileOpenWithCallbacks. I’m not by my work computer so I can’t give you exact code, but here’s the general process:

    • Use fopen/fread to read the given file into a memory buffer array. Use a simple C array and not an NSArray or NSData – you need speed and you need for it to be compatible with the next step.
    • Create some basic C function callbacks for read / get size.
    • Use AudioFileOpenWithCallbacks with the callbacks you wrote to open
      the audio file in memory.
    • Use ExtAudioFileWrapAudioFileID to start decoding the file in memory.
      This is in replacement of ExtAudioFileOpenURL.

    If you Google +AudioFileOpenWithCallbacks +ExtAudioFileWrapAudioFileID, you’ll find that some folks have already done this and published their code.

    I’m not sure what you mean by non-standard mp3 data, so you should try to play the file using another app to see if it will be compatible.