开发者

AudioQueueStart fail -12985

I made a streaming music player and it works fine in the foreground. But in the background iOS4, 开发者_StackOverflow中文版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.


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.


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.


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.


I have the same problem. I registry the AudioSessionInterruptionListener, pause the audio when phone call, resume it after the call end. but get -12985 error code when call AudioQueueStart to resume. My solution is that I try to call AudioQueueStart after 0.02s. I don't know the reason.


On iOS7, AudioQueueStart was returning '!int' ('tni!'), though i'm sure no one would be surprised to find that it's not documented in the docs or headers. It was the same issue, though, and the same fix (setting the audio session to active in the background task handler) worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜