0

I'm trying make a simple app to record audio from MIC but I have seen examples 1000 but all give me the same error:

java.lang.RuntimeException: setAudioSource failed. at android.media.MediaRecorder._setAudioSource(Native Method)

I don't find the solution, and this occur at emulator (without MIC, I know) and my terminal (Note 4 - Android 6.0.1).

public class Audio {

private MediaRecorder myAudioRecorder;
String mFileName;

public Audio(Context contexto)
{
    myAudioRecorder = new MediaRecorder();
}

public void startRecord(String name)
{
    myAudioRecorder=new MediaRecorder();
    myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);   <== ** HERE ERROR **
    myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
    myAudioRecorder.setOutputFile(name);
}

public void stopRecord()
{
    myAudioRecorder.stop();
    myAudioRecorder.reset();
}}

Is there any way to know if another application has held the microphone?

Another thing, I add to my manifiest both permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

I have seen this soution too android mediaRecorder.setAudioSource failed but I continue without solution.... I don't know how I can make it.

Thanks for all.

Community
  • 1
  • 1
Drako
  • 769
  • 1
  • 8
  • 23
  • 1
    You need to request the permission to use RECORD_AUDIO on 6+. https://developer.android.com/training/permissions/requesting.html – DeeV Nov 02 '16 at 13:47
  • I just try it and, for the moment, no crash like before :-D Thanks! – Drako Nov 02 '16 at 14:06

0 Answers0