I am writing an application that runs as a background service recording and analyzing audio recorded from the microphone. When my app is running I can't use other apps that use the microphone (e.g. phone, voice recording, etc...).
My question is - Is there a way to share the microphone stream in Android? Maybe by using the NDK? If not, is it possible to receive an indication (e.g. a BroadcastIntent) that another app is requiring the microphone?
Simple Answer would be "NO" , This is just because Audio Recording Method is synchronized. So Two or more resources can not attempt it simantenously. Doing so might sometime force close the applicatio.
I know this is old, but you may be able to kill/reactivate the microphone connection every few minutes to simulate a shared microphone resource. This is an untested hack...
Essentially:
- Set a timer to disconnect from the mic every few minutes
Hopefully, if another app is trying to collect mic data, it can
while blocking other apps from collecting at the same time
- Attempt to reconnect and test for data
if the other app has the mic and is blocking data then you can
try to reconnect at some time in the future.
I haven't tested this but I need a solution too so I'll post code if it works.
Recording audio/video, while other applications are running , is possible. I've done it in Sony Xperia Z1, continuously recorded videos and calls with a downloaded screen recorder. However, I do believe that this was a glitch of some sort, as it stopped being able to record after some time (about 2 months)and started showing an error which says that the microphone is being used by another application...