-2

Possible Duplicate:
AudioQueueStart fail -12985

This was asked once before but I tried implementing one of the suggested answers (nothing was accepted) and didn't get any luck.

I should mention that I've set the proper background mode in the pList.

Basically, I'm trying to play a sound in didEnterRegion. Here's my code:

- (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];   
}

The url is ok since it'll play in the foreground. It also seems ok in the console log:

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)

I'm assuming that that last line is the error given when trying to play audio.

Any ideas?

Community
  • 1
  • 1
ari gold
  • 2,074
  • 3
  • 25
  • 51
  • I see the similarities between our two questions, but I would suggest that they are not exact duplicates. He is using AudioQueue buffers and I am not. Sometimes there are more than one way to do the same thing, no? – ari gold Sep 13 '12 at 18:19
  • I saw that one too but not only is it unclear and worded poorly, it has no accepted answer. – ari gold Sep 13 '12 at 18:34
  • Mentioning previous questions that seem similar to your problem is a good beginning, but you should really make the reasons they didn't help clear and explicit in your post. "Didn't get any luck" isn't much of a description. "The solution there is using X library that I can't use because Y." "That code doesn't apply because I'm not using an AudioQueue." "I used the code in that question, and my computer caught on fire" If you particularly have trouble interpreting or implementing a solution from another question, it's fair game to ask about that, as long as you are specific and detailed. – jscs Sep 13 '12 at 19:07

1 Answers1

0

Add this:

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

Refer play-mp3-files-with-iphone-sdk link

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • I tried that but it didn't work. I got the same error. Out of curiosity, why set the delegate? What delegate protocol should I implement? – ari gold Sep 13 '12 at 06:20