iPhone SDK: Audio Queue control
Posted
by codemercenary
on Stack Overflow
See other posts from Stack Overflow
or by codemercenary
Published on 2010-04-14T12:21:09Z
Indexed on
2010/04/14
12:23 UTC
Read the original article
Hit count: 594
Hi all,
I am new to the audio queue services so I have taken an example from a book called iPhone Cool Projects where it describes how to stream audio. I want to extend this to being able to play a continuous playlist of links to mp3 files like an internet radio.
The problem with the example code it that it does not detect when a stream ends and does not call AudioQueueStop at any point, so I added a counter to number of buffers added to the queue, and then decrement this counter each time audioQueueOutputCallback is called by the queue.
This works fine except if when the buffer count goes to 0, and then I add a call AudioQueueFlush(audioQueue) and then AudioQueueStop(audioQueue, false) I get an error.
If I only call AudioQueueReset, it continues to load the buffers again, but plays them out faster then it loads them... getting stuck in a loop and then crashing.
2010-04-14 13:56:29.745 AudioPlayer[2269:207] init player with URL
2010-04-14 13:56:29.941 AudioPlayer[2269:207] did recieve data
2010-04-14 13:56:29.942 AudioPlayer[2269:207] audio request didReceiveData
2010-04-14 13:56:29.944 AudioPlayer[2269:207] >>> start audio queue
2010-04-14 13:56:29.960 AudioPlayer[2269:207] packetCallback count 2
2010-04-14 13:56:29.961 AudioPlayer[2269:207] add buffer: 1
2010-04-14 13:56:29.962 AudioPlayer[2269:207] did recieve data
2010-04-14 13:56:29.963 AudioPlayer[2269:207] audio request didReceiveData
2010-04-14 13:56:29.963 AudioPlayer[2269:207] packetCallback count 1
2010-04-14 13:56:29.964 AudioPlayer[2269:207] add buffer: 2
2010-04-14 13:56:29.965 AudioPlayer[2269:207] packetCallback count 13
2010-04-14 13:56:29.967 AudioPlayer[2269:207] add buffer: 3
2010-04-14 13:56:29.968 AudioPlayer[2269:207] done with buffer: 3
2010-04-14 13:56:29.969 AudioPlayer[2269:207] done with buffer: 2
2010-04-14 13:56:29.974 AudioPlayer[2269:207] done with buffer: 1
So this loop continues some 20 - 30 times and then it crashes.
The first time it plays an audio file it queues up the buffers and then plays sound, but doesn't callback to delete them until some 100 or more have been played. Can anyone explain this behavior?
I read that there was a limit of 1 audio queue for MP3 playback for the iPhone. Is that still true? If not then I suppose I should use another audio queue for the next mp3 stream.
I've had a look through the apple docs but it doesn't explain this in any particular detail.
A better insight into this would be great. TIA.
© Stack Overflow or respective owner