I'm trying to record a sound in java in android but the app crashes with this exception:
E/AndroidRuntime: FATAL EXCEPTION: Timer-0 Process: com.example.mathieu.telefony1, PID: 31353 java.lang.RuntimeException: setAudioSource failed.
But it is very strange, because I added it to the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application...
and here is my code to record a sound:
MediaRecorder mr = new MediaRecorder();
File file = new File(OUTPUT_FILE);
try {
mr.setOutputFile(OUTPUT_FILE);
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mr.prepare();
mr.start();
Thread.sleep(1000);
mr.stop();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}