I try to automatically play a sound file (which is not part of my application package and is not a notification sound) after receiving a remote notification. I want this to happen if the application is in the foreground or in the background when receiving a notification.
I use the Amazing Audio Engine as a wrapper around major audio libraries. In my App Delegate didReceiveRemoteNotification I create an Audio Controller and add AEAudioFilePlayer to it AEAudioFilePlayer this:
NSURL *file = [NSURL fileURLWithPath:sourceFilePath]; AEAudioFilePlayer *notificationPlayer = [AEAudioFilePlayer audioFilePlayerWithURL:file audioController:_notificationController error:NULL]; notificationPlayer.completionBlock = ^{
However, the sound does not play! My logs display the following errors:
2014-08-18 06:21:28.003 MyApp[394:60b] TAAE: Setting audio session category to AVAudioSessionCategoryPlayback 2014-08-18 06:21:28.019 MyApp[394:60b] Couldn't activate audio session: Error Domain=NSOSStatusErrorDomain Code=561015905 "The operation couldn't be completed. (OSStatus error 561015905.)" 2014-08-18 06:21:28.024 MyApp[394:60b] TAAE: Audio session initialized (audio route '<AVAudioSessionRouteDescription: 0x178006720, inputs = (null); outputs = ( "<AVAudioSessionPortDescription: 0x1780067f0, type = Speaker; name = Speaker; UID = Speaker; selectedDataSource = (null)>" )>') 2014-08-18 06:21:28.034 MyApp[394:60b] 06:21:28.033 ERROR: [0x1938e42a0] >aurioc> 783: failed: '!pla' (enable 2, outf< 2 ch, 44100 Hz, Int16, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>) 2014-08-18 06:21:28.037 MyApp[394:60b] 06:21:28.037 ERROR: [0x1938e42a0] >aurioc> 783: failed: '!pla' (enable 2, outf< 2 ch, 44100 Hz, Int16, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)
While viewing the pla error, I found this link: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html
which indicates that this type of error can occur if the list of properties of the application information does not allow the use of audio or if the application is in the background and uses a category that does not allow background sound.
But my plist contains audio as the background mode, my audio sessions category is AVAudioSessionCategoryPlayback, and for the parameters of my category it is AVAudioSessionCategoryOptionMixWith Other.
How to get the sound that will play when you receive a remote notification?