Question

I am writing an application that uses MediaRecorder for recording audio. ( I use Android 2.1 )

  1. Before start recording I want to know the microphone's state (is it busy or no)?
  2. If the microphone busy, can I get exclusive access to it?

Thanks in advance!

Was it helpful?

Solution

Answer to 1 question: After reading many articles I realized that it was impossible.

OTHER TIPS

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();

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top