Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release AudioRecord android when other app request for recording

I have an audio recording service in my app which will record the sound continuously. So, it will always occupy the AudioRecord. It means no other app can use audio recorder as it is already occupied by the service. Is there any way to notify that other app is requesting for audio recorder(so that I can release it) and also when the app releases it(so that I can assign it back to the service)?

like image 548
berserk Avatar asked Sep 05 '14 09:09

berserk


Video Answer


2 Answers

Maybe a possible way is to create a BroadcastReceiver which receives an event from the app which is requesting the control over the mic source. The onReceive() method should interact with the service and release the resource. When the other app is finishing it can revert the process to start the service again. If you can't get control over the behavior of the requesting app I think there's a slightly different problem. Anyway:

The problem is all about knowing when the resource is being requested, this can be done through AudioManager intent types. Be sure to check Managing audio focus which talks about audio focus loss in TRANSIENT way!

like image 172
fiipi Avatar answered Oct 19 '22 23:10

fiipi


As @Rekire mentioned, there is possibly no way to achieve this. Also, AudioManager provide no such broadcasts, so it is not possible for different apps. Maybe rooting the device is the only option.

like image 44
Mukesh Rana Avatar answered Oct 20 '22 00:10

Mukesh Rana