RemoteIO and Recording AAC on iOS 6 - iphone

Is anyone using RemoteIO for recording AAC audio on iOS 6? I've noticed that when I'm doing this, it kills the media server on interruption and my interruption callbacks are never called on iOS 6.0.
Also, because the media server goes down, it makes recovering a bit difficult.
Is anyone else seeing this or worked around it?

Problem solved. Use the software codec:
// specify codec
UInt32 codec = kAppleSoftwareAudioCodecManufacturer;
int codecSize = sizeof(codec);
status = ExtAudioFileSetProperty(recorderState.audioFile,
kExtAudioFileProperty_CodecManufacturer,
codecSize,
&codec);
Before I was using kAppleHardwareAudioCodecManufacturer... evidently the hardware codec can't handle interruptions. Hope others find this useful!

I am having a similar problem. I am trying to record AAC audio using remoteio, for pretty much all the same reasons you described here:
http://lists.apple.com/archives/coreaudio-api/2012/Oct/msg00135.html
My current problem isn't even with interuptions. If I dispose of my audio unit and set my audio session to inactive on being moved to the background, I still have the media server get killed when I try to reactivate my session when the app reloads.
My basic flow that is dying is this:
- set up an active audio session for recording
- setup an audio unit & and file in preparation for the user pressing the 'record' button
- user backgrounds the app, in order to tear down everything I dispose of my audio unit and deactivate my session, but I don't clean up my extaudiofile at this point
- I open voice memos, and then immediately close it
- reopen my app and hit record.
- when I try and set the session to active, mediaserverd dies. Switching to the software codec didn't fix it!
If you have learned any more about this craziness I would love to hear what you figured out.
Thanks.

Related

Starting audio in locked screen mode not working

I am working on a timer App with alerts. When the screen is locked I would like to have my alerts/Text To Speech keeping to work. It works for some time between 30 to 60 sec and then alerts stops working but the timer is continuing to work as when I unlock the phone the timer progressed and works. I went through many posts and I didn't find a solution. It looks like new audio cannot be fired in lock down mode (some posts said new audio sounds cannot be triggered in lock down but continuity of audio is working). I finally found this post -> AVFoundation playing audio in background/on lock screen in Swift
so I added following lines in my code:
// to authorize background music in parallel
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient)
try? AVAudioSession.sharedInstance().setActive(true)
// to play audio in background, lock screen mode
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
and in info.plist I have this entry:
The result is that short audio sounds are working (I trigger them every 30 sec) only if I lock the screen during an audio, if I do it between two sounds it stops. I spent many days on searching solutions but nothing works, can someone please help here?
Spending again some hours to search further on this topic and what I found: -> https://developer.apple.com/forums/thread/77937
seems really a problem for many people but I don't understand why we don't find any solution as I saw many apps with this feature working, if you see any good answer please tell me.
As no one had an answer I contacted Apple Developer Technical Support and the response was a bit surprising but there is no "clean way" to do it, here the answer I got:
"To continue playing audio from the background, continuously play audio in the background (mostly this will be silent, except for when you have a new “alert”)"
I tested it with a silent.wav file of 60 sec that I fire every 55 sec and it works!

How do I put iOS application in background mode, with audio option set?

So my application for iphone4 reads data from the accelerometer and sends it to another application via tcp sockets. I need my app to work in background mode, so what I did was:
I put an mp3 file in the application's Documents folder
I used AVAudioPlayer library to play the file in a loop. It works.
I edited Info.plist and added option "required background
modes" with "audio" on.
Still, the scheduler suspends the application whenever I press the iphone's home button. Is there anything I missed?
I read apple's documentation, but I didn't find a solution. A few thoughts on this:
do I have to edit appDelegate.m?
is it because I use AVAudioPlayer instead of the iPod?
is it because I play an audio file from the application documents
folder?
I read about one person changing iOS Development Target from 4.0 to
3.2.1, but that didn't work for me.
And finally, say I get this to work, would the application still be getting data from the accelerometer?
On a side note, I don't want to submit the application to the App Store.
No, you will not receive accelerometer notifications in background mode. As far as I know, it is not possible. Check Executing Code in Background.
If you read the docs carefully, you will know that the whole background code model is based on responding to specific events (location and voip modes).
As for the audio mode here is an extract from Apple:
Your application should limit itself to doing only the work necessary
to provide data for playback while in the background. For example, a
streaming audio application would download any new data from its
server and push the current audio samples out for playback. You should
not perform any extraneous tasks that are unrelated to playing the
content.
Not sure whether you have solved your issue or not since this question was posted more than one year ago. Also, not sure whether playing audio is a must in your app or not. If both answers are no, my recent investigation may help a bit.
Here are how I get my app getting accelerometer data at the background
1. Follow this tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ to get the background location working.
2. Follow this tutorial http://jonathanhui.com/ios-motion to get the accelerometer working.
Then you can get an app collecting accelerometer data at the background. Hope this helps.

Adobe Air + iphone microphone problem: low volume after SampleDataEvent.SAMPLE_DATA event

I am developing and iPhone app with Adobe Air 2.6 using Flash CS 5.5. I am trying to capture microphone input and then playback an mp3 file. The problem is now, that once I capture the microphone data with the SampleDataEvent.SAMPLE_DATA event, the volume of the playback mechanism seems to be decreased significantly.
To reproduce:
playback a (remote) mp3 file and the volume is ok
get the microphone and add the event listener (see code below), the listener function does not even need any code for this problem to occur.
same as step 1 (playback remote mp3) and the volume is very low.
// add the event listener
_microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
private function onSampleData(event:SampleDataEvent):void
{
//while(event.data.bytesAvailable > 0) {
// _buffer.writeFloat(event.data.readFloat());
//}
}
// call this before playing back the mp3
_microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
When testing with the Flash IDE, the problem does NOT occur and everything works as expected. Tested on iPhone 3GS with iOS 4.3.3.
If anybody experienced this problem I would greatly appreciate your insights.
UPDATE:
I think it is not an AIR problem per se. After using the iOS Microphone the whole app almost mutes itself, that is also the case for the typing on the virtual keyboard (which does not come from AIR). Doesn't really help me but maybe somebody knows how to shut down the microphone in an app so that speaker levels get back to normal?
UPDATE 2:
Here you can see a running example from Adobe http://tv.adobe.com/watch/adc-presents/developing-for-ios-with-air-for-mobile-26/, note that the speaker volume of the iphone in the live demo is really low too. So that must be a pretty huge bug then, making the microphone on the iPhone unusable.
download and use AIR 3 sdk
then set
SoundMixer.useSpeakerphoneForVoice = true;
SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
and your problem should be solved

How to play a sound while running in the background?

I need to be able to play a sound while running the application in the background.
I tried with UILocalNotifications but the file needs to be part of the bundle, and that will not be the case, as I need to generate the sound files on the fly...
So is there any way that I can play a sound while running in the background?
Thanks.
You can't, unless you continuously play audio and have the appropriate audio session category set for your app... then your app doesn't go to sleep, it continues to run (again so long as audio is playing).
This is part of the design limitations of iOS multitasking.
Apple has allowed people to get away with having a continuously looping blank audio file (AVAudioPlayer loop = -1 with a 1-sec blank CAF file) if the app is primarily audio related and it is obvious to the user that this has battery life implications (and can be disabled by the user), but YMMV... you app can also be rejected for this.

Can anybody explain how the AudioSessionSetActive(true/false) function works in the iPhone OS?

Activating audio session interrupt audio sessions belonging to built-in applications running in the background, depending on categories and priorities. Deactivating audio session allows other, interrupted audio sessions to resume.
activating audio session ( AudioSessionSetActive(true) ) was working properly,but deactivating audio session ( AudioSessionSetActive(false) ) was not working. can any body suggest me how to deactivate audio session and resume the interrupted audio.
This now dated blog entry explained it well.
Just substitute "OpenAL" with "Your Audio System".
Instead of using AudioSessionSetActive(false)
You should use the following
AudioSessionSetActiveWithFlags(false, kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation);
to notify other applications to resume their playback.
To understand AudioSession, visit Apple dev