Reputation: 1
i found some useful tips here but to be sure if my requirements are possible to implement here is a short list.
i have an app which runs in background most of the time. the app "lives" for up to some hours and on a certain point i need to play an alarm sound.
so what i have found is that i need to start a AVQueuePlayer and add a mutesound which is playing constantly until i need to play my other sound. is that right?
so i create a singleton class (SoundService) where i initialize the silentsound and the alarmsound in the queue player. when the app is going to the background i start the player and play the silent sound. if i then need to play my alarm sound while the app is in the background it should work, am i right?
right now my implementation does not work, but am i on the right way?
thanks
Upvotes: 0
Views: 331
Reputation: 2359
You cannot initiate audio in the background. The only thing the audio background mode allows you to do is to continue producing sound as the app goes from the foreground to the background.
However, if your app is capable of receiving remote events, and if it has produced sound so that it is the remote event target, then, with audio background mode, it can go on being the remote event target and thus can produce sound in the background, as long as no other app becomes the remote event target in the meantime.
The most reliable way to produce a sound while in the background is by attaching the sound to a local notification.
notification.soundName = UILocalNotificationDefaultSoundName;
notification.soundName = @"mySound.caf";
Make sure the sound is actually in your app’s bundle, is in the correct format (linear PCM or IMA4). You can convert from wav and mp3 using:
afconvert -f caff -d LEI16@44100 -c 1 original.wav mySound.caf
Upvotes: 1