简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM