Search
Recommended for You

Thoughts on AVFoundation


In the beginning, or at least the iPhone's beginning, there was Celestial. It offered a fabulous QuickTime-esque approach to handling media of all kinds. Of course, this was back in the days of the first jailbreaks and there was no official SDK. When the SDK finally did roll around, its Audio Queue approach to handling audio playback and recording proved to be an extreme disappointment.

A quick glance through the Audio Queue Services programming guide reveals both the power and complexity of the service. Involving pages of low-level programming just for even the simplest audio requests, Audio Queues are perfect for serious performance-driven developers but lack the easy-to-use hooks that Celestial had provided. With Celestial, you could load a URL and then just play it.

I soon found that the Celestial AVController class was lurking in the SDK's new Media Player framework but it was hidden away. You could tunnel down through several layers of undocumented classes to arrive at the MPAVController and MPArrayQueueFeeder objects that were simply repackaged Celestial items. By using non-published APIs, developers would still be putting themselves outside the lines for App Store approval and of course run the risks that updates might fail when new firmware was released. Apple does not stand behind unpublished APIs the way it does with its official classes.

So it was a great thrill when SDK 2.2 debuted, bring AVAudioPlayer as part of the new AVFoundation class. It provides the same Celestial calls we've seen back since day one, but it does so officially. You can load audio, play it, pause it, adjust its volume and so forth. You can even enable metering and check peak power.

What's still missing though, is the AVRecorder class. This companion to AVAudioPlayer has not yet hit the big times and I can only hope that Apple has it still under wraps, ready to add to the next SDK version. Celestial's AVRecorder offers insanely simple recording abilities. You can start recording, monitor file size and levels, and stop recording. It doesn't get any easier than that.

Until 2.0 debuted, AVRecorder provided a simple way to capture sound as AMR files. From 2.0 and on, that changed to AIFF. But as Celestial was moved from a public framework to a private one, the recording ability remains off-limits. At this time, you still need to use Audio Queues. That's a pain, and far harder than AVRecorder's simple start/stop interface.

So here's the bottom line: I'm really happy that AVFoundation has appeared, even though it appears to offer just a single basic playback class. But until it offers the recording component, it remains preliminary. Call it half-baked if you like because Apple's only offered a taste and there's still a ways to go. Keep your eye on this framework because it offers the possibility of a much more CocoaTouch friendly approach to audio tasks on the iPhone. And keep your fingers crossed that AVRecorder joins its sibling as part of the next SDK release.

AddThis Social Bookmark Button
Comments (2)

2 Comments

Aston said:

AVFoundation really helpfull. When I saw the "Audio Queue Services" I even didn't want to continue have deal with sound in iPhone. AVFoundation make life easier. But I have found a problem with it - on some machines it's missing (even on SDK 2.2.1 which have to have it). I founded this framework in other dir but it always gives fail's on play or prepareToPlay calls

StevenArnold said:

I notice that when the iPhone goes to sleep, any sound being played by the AVFoundation framework stops. It restarts when you wake the iPhone back up, not sure if it restarts from the beginning or continues where it left off, or continued playing even while the iPhone was asleep but was just inaudible during the time it was asleep.

Does anyone have any idea how to make an AVFoundation track continue to play even when the iPhone is in sleep mode?

steven

Leave a comment