How to combine AudioQueuePause with AudioQueueGetCurrentTime to resume audio Playback in iPhone SDK?
My iPhone app plays a streaming audio from the internet.
I need to combine AudioQue开发者_如何学CuePause with AudioQueueGetCurrentTime to pause the audio stream and then resume the playback when the user presses the play again.
How do I implement AudioQueuePause with AudioQueueGetCurrentTime, for pausing and resuming the audio playback?
Actually I didn't need to combine AudioQueuePause with AudioQueueGetCurrentTime to pause the audio stream, and then resume it afterwards when requested.
First I created two buttons (IBActions in my PlayerViewController.m), one for pause, and another for resuming the audio, besides the one I already had for start/stop. When starting it had to buffer first and then the audio would play. If I pressed the button again it would stop, getting rid of the current WiFi or 3G connection.
Then I just had to use AudioQueuePause(inAudioQueue); in a -(void)pauseAudioStreaming method and AudioQueueStart(inAudioQueue, NULL); in a -(void)resume method. The NULL means that the audio will start ASAP, in the exact point where I paused it (then I concluded that there is no need to get the current time, using AudioQueueGetCurrentTime) like so:
- (void)pauseAudioStreaming
{
AudioQueuePause(inAudioQueue);
}
- (void)resume
{
AudioQueueStart(inAudioQueue, NULL);
}
Now it doesn't need to buffer again from the beginning of the audio, but it will pause and resume very fast when requested.
精彩评论