Tag Archive for 'Stream'

Playing AAC+ Streams on iPhone

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).

Shoutcast streams on the iPhone

So Hamed and I were talking about streaming RJ to an iPhone when we realized that there wasn’t much out there to do it outside of a php script or two that sort-of worked.  Today I made progress on a POC (.net app) that streams (choppy) audio from a Shoutcast stream to an iPhone for about 30 seconds before crapping out. I’ll try to find some time to fix it up next week and throw it out there. It’ll be a single user single stream sort of thing, for now, since it’s much easier to deal with. I need to get over this whole 30 seconds then croak business, make it so it gracefully recovers from client disconnects, and optimize its performance a bit (choppy audio is useless). Hopefully I can finish it sometime next weekend as I’ll be busy this weekend.