Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioQueueStart fail -12985

I made a streaming music player and it works fine in the foreground. But in the background iOS4, it doesn't play the next song automatically. ( remote control works ) The reason is AudioQueueStart return -12985.

I already check the audio session. it just fine. I use AudioQueueStart when it start to play the music. How can you remove AudioQueueStart?

- (void)play
{
    [self setupAudioQueueBuffers];    // calcluate the size to use for each audio queue buffer, and calculate the // number of packets to read into each buffer
    OSStatus status = AudioQueueStart(self.queueObject, NULL); 
}

I read the answer in the web about the AudioQueueStart fail subject.

One thing to check is that the AudioSession is active first. In my case, I had previously set the session to inactive between song changes before starting a new song:AudioSessionSetActive(false);

Once I removed this AudioQueueStart works just fine from the background.

like image 346
ys1103 Avatar asked Dec 03 '10 19:12

ys1103


3 Answers

In my experience, the -12985 message occurs because another app already has an audio session active when you try to start playback in your app. Options are to 1) instruct the user to close the other app, or 2) set mix mode (see kAudioSessionProperty_OverrideCategoryMixWithOthers).

The disadvantage of mix mode is if you depend on lock screen art or remote controls, they won't work with mix mode set.

like image 71
Robert Diamond Avatar answered Oct 31 '22 12:10

Robert Diamond


I also faced with such problem week ago. I've spent two days to find solution and I found it. May be this link will help (it is official answer): http://developer.apple.com/library/ios/#qa/qa1668/_index.html

Make sure that you activate session from applicationDidEnterBackground task handler. Now my application can play sound in background.

like image 20
VictorT Avatar answered Oct 31 '22 13:10

VictorT


See this.

You probably need to include the following:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Towards the bottom there is a reiteration of the how important that line is. As it is not mentioned in any of the three main audio audio guides (AVFoundation, AudioSession, or AudioQueue) it can easily be missed.

like image 44
ari gold Avatar answered Oct 31 '22 11:10

ari gold