Is it possible to share audio input (Microphone) stream in Android?

社会主义新天地 提交于 2019-11-30 05:24:46

问题


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?


回答1:


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.




回答2:


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:

  1. 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
  2. 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.




回答3:


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...




回答4:


Yes, with Android 10 you can.

Before Android 10 the input audio stream could only be captured by one app at a time



来源:https://stackoverflow.com/questions/9758946/is-it-possible-to-share-audio-input-microphone-stream-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!