0

I have tried everything:

-setup info.plist Required background modes : App plays audio;

-setup player:

 [[AVAudioSession sharedInstance] setDelegate: self];

// allow app continue to play when the screen is locked
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                       error:nil];

UInt32 doSetProperty = 0;
AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers,
                         sizeof (doSetProperty),
                         &doSetProperty
                         );

// Registers the audio route change listener callback function
AudioSessionAddPropertyListener (
                                 kAudioSessionProperty_AudioRouteChange,
                                 audioRouteChangeListenerCallback,
                                 self
                                 );

// Activates the audio session.

NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];

[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

What am I forgetting? Is there something wrong?

JOM
  • 8,139
  • 6
  • 78
  • 111
ikanimo
  • 481
  • 1
  • 4
  • 18
  • can you email me your code. I have worked on it, and it's working properly, second thing is that have you tested it on device or just simulator. In case of simulator, it won't work. – Khalid Usman Apr 24 '12 at 09:08
  • Follow this link http://stackoverflow.com/questions/10276096/cant-beginreceivingremotecontrolevents-in-ios/10278392#10278392. If even you don't got it, then please email me your code, I will solve it insha Allah, khalid0491@gmail.com – Khalid Usman Apr 24 '12 at 09:20

1 Answers1

1

You need to set the Audio Category to Playback:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

If you then want to allow mixing audio with other apps, you can add this option, just make sure to do this before setting the audio session to active.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];

Now you can set the audio session to active:

[[AVAudioSession sharedInstance] setActive:YES error:&error];
Josh
  • 621
  • 6
  • 10