-2

可能重复:
AudioQueueStart 失败 -12985

之前有人问这个问题,但我尝试实施建议的答案之一(没有被接受)并且没有得到任何运气。

我应该提到我已经在 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)

我假设最后一行是尝试播放音频时给出的错误。

有任何想法吗?

4

1 回答 1

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链接

于 2012-09-13T05:58:29.767 回答