XXX
XXX

Reputation: 9072

Microphone's state

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!

Upvotes: 0

Views: 852

Answers (2)

Aleksei
Aleksei

Reputation: 21

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

    }

Upvotes: 0

XXX
XXX

Reputation: 9072

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

Upvotes: 1

Related Questions