Hi all, I have created a few classes that should make it extremely easy to integrate audio file selection and playback on iOS devices. I have included them as part of my dRowAudio module as one of the classes relies on the FifoBuffer present in it but it shouldn’t be too much work if you wanted to pull them out. I would recommend just dumping the module in your juce/modules folder and using the Introjucer to generate a project through.
The three classes are as follows:
This is a very simple class that simply shows the native audio picker and allows the user to select one or more tracks. To be notified of when tracks are selected register yourself as an AudioPicker::Listener. This callback will receive an array of MPMediaItems disguised as void*s which you can the use in one of the classes below. This class closely follows the design of aiit’s ImagePicker class so thanks goes to him for that.
As the name suggests this is a juce::AudioFormat that is capable of reading files from the iOS device. Due to the strict sandboxing rules there is no way to get direct access to the audio files on a device so this class deals with all the underlying AVFoundation and AudioToolbox gubbins required to get copies of the actual samples. This should be able to plug seamlessly into an existing juce audio chain.
While the AVAssetAudioFormat is fine in most situations, you may want direct access to an audio file. Because the AVFoundation framework bufferes the audio reading on a background thread sometimes it is helpful to have proper access to an audio file. This class takes an MPMediaItem returned from the AudioPicker and converts it into a 16-bit WAV PCM in your app’s documents folder. It returns a file object which you can use just like any other file on a proper OS.
The classes are all heavily documented and there are code examples in there too. Due to the Obj-C nature of some of the objects returned there are a number of void* instances in the interfaces. These should be labelled clearly as to what they actually refer to and where necessary the classes have static helper methods to convert them to String’s etc. which you can easily pass around.
Feel free to try them out and any feedback is welcome. These classes are still in the beta stage while I figure out how best to deal with passing around the void’s so the return types, method names etc. may change. I will be very clear about this in the comments if they do. I’ll also try and hook up a little demo if I get some time.