AudioQueueStart fail -12985

自古美人都是妖i 提交于 2019-11-28 00:29:57

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/4349173/audioqueuestart-fail-12985

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!