2012-09-13 133 views
-2

可能重複:
AudioQueueStart fail -12985從背景播放音頻時出錯。 AudioQueue錯誤12985

這是問once之前,但我試圖執行參考答案中的一個(沒有被接受)並沒有得到任何運氣。

我應該提到我已經在pList中設置了正確的背景模式。

基本上,我試圖在didEnterRegion中播放聲音。這是我的代碼:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 
    NSLog(@"MapViewController - didEnterRegion"); 
    NSLog(@"MVC - didEnterRegion - region.radius = %f", region.radius); 

    // code to get the url (removed for simplicity) 

    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 

    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; 
    [audioSession setActive: YES error: nil]; 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

    self.regionPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
    NSLog(@"self.regionPlayer.url = %@",self.regionPlayer.url); 
    [self.regionPlayer play]; 
} 

該網址是好的,因爲它會在前臺播放。它也似乎在控制檯日誌中確定:

Sep 12 22:33:47 unknown MLTM[4995] <Warning>: MVC - didEnterRegion - region.radius = 250.000000 
Sep 12 22:33:47 unknown MLTM[4995] <Warning>: url = file://localhost/var/mobile/Applications/EFD6A583-5685-4D7C-BF8E-C8CFEA9E0D03/MLTM.app/party%20mix%207.caf 
Sep 12 22:33:47 unknown MLTM[4995] <Warning>: self.regionPlayer.url = file://localhost/var/mobile/Applications/EFD6A583-5685-4D7C-BF8E-C8CFEA9E0D03/MLTM.app/party%20mix%207.caf 
Sep 12 22:33:48 unknown Console[4179] <Notice>: TestFlight: Team Token is recognized 
Sep 12 22:33:48 unknown mediaserverd[44] <Error>: 22:33:48.087 <AudioQueueServer> AudioQueue: Error -12985 from AudioSessionSetClientPlayState(4995) 

我假設,最後一行是試圖播放音頻時給出的錯誤。

任何想法?

+0

我看到我們的兩個問題之間的相似性,但我會建議他們沒有確切的重複。他正在使用AudioQueue緩衝區,我不是。有時候有不止一種方法可以做同樣的事情,不是嗎? –

+0

我也看到了這個,但不僅不清楚,而且措辭不佳,沒有接受的答案。 –

+0

提到與您的問題看起來相似的以前的問題是一個好的開始,但您應該真的提出他們在您的文章中沒有明確和明確的理由。 「沒有得到任何好運」不是很多描述。 「那裏的解決方案是使用X庫,我不能使用,因爲Y.」 「該代碼不適用,因爲我沒有使用AudioQueue。」 「我在這個問題中使用了代碼,並且我的電腦着火了。」如果您在解釋或實施另一個問題的解決方案時遇到困難,只要您具體而詳細,詢問這個問題是公平的。 –

回答

0

補充一點:

register **UIBackgroundModes** in info.plist for background playing 
[[AVAudioSession sharedInstance] setDelegate: self]; 
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil]; 

參考play-mp3-files-with-iphone-sdk鏈接

+0

我試過了,但沒有奏效。我得到了同樣的錯誤。出於好奇,爲什麼要設置代表?我應該實施什麼委託協議? –