Microphone's state
-
27-10-2019 - |
Pergunta
I am writing an application that uses MediaRecorder for recording audio. ( I use Android 2.1 )
- Before start recording I want to know the microphone's state (is it busy or no)?
- If the microphone busy, can I get exclusive access to it?
Thanks in advance!
Solução
Answer to 1 question: After reading many articles I realized that it was impossible.
Outras dicas
It's an old question but I show the way I solve this problem. Maybe someone will need this help. Note: it's a dirty way but it worked for me.
You can try/catch MediaRecorderObject.start(). You will get an exception if the mic is busy
MediaRecorder myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
}
catch (Exception exception) {
Toast.makeText(getApplicationContext(), "Mic in use", Toast.LENGTH_LONG).show();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow