You can play AAC+ Streams on iPhone just like a standard MP3 stream (Fetch w/ NSURLConnection, pass filled buffers to the AudioQueue), but pass the AudioFileTypeID “kAudioFileAAC_ADTSType” to AudioFileStreamOpen instead of “kAudioFileMP3Type.” How does one go about checking what type of stream they’re dealing with? Check the content-type (parse it out of headers or the initial response data — that depends on the stream server you’re dealing with):
if ([contentTypeLine rangeOfString:@"audio/aac"].length > 0)
{
audioFileType = kAudioFileAAC_ADTSType;
//Pause and resume so we reinitialize the audio stream with the new file type (AAC+)
[self restartAudioQueue];
}
where restartAudioQueue does something along the lines of the following:
-(void)restartAudioQueue {
[self resetAudioQueue];
AudioFileStreamOpen(&audioState, &PropertyListener, &PacketsProc, audioFileType, &audioState.streamID);
}
and resetAudioQueue calls AudioFileStreamClose, AudioQueueStop and AudioQueueReset as well as cleaning up buffers, etc.
Note that it’s not necessary to cancel and recreate your NSURLConnection — it’s (obviously) independent of the AudioQueue.
Don’t forget to parse out your metadata or you’ll get skips!
Update: AAC+ playback seems to be broken in iPhone 2.1. I’ve filed a bug report w/ Apple about playback skipping w/ 2.1 (same code works great w/ 2.0).

Recent Comments