Android Record Audio problem

I found code for recording sound, but I always get:

The setOutputFile (FileDescriptor) method in the MediaRecorder type is not applicable for arguments (Uri)

So, how do I need to describe the file path, that it works?

// Prepare recorder source and type MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // File to which audio should be recorded File outputFile = getFileStreamPath("output.amr"); Uri target = Uri.parse(outputFile.getAbsolutePath()); recorder.setOutputFile(target); // Get ready! recorder.prepare(); // Start recording recorder.start(); // Stop and tidy up recorder.stop(); recorder.release(); 
+4
source share
1 answer

You are trying to pass a Uri parameter to a method that does not expect this. Just replace recorder.setOutputFile(target) with:

 recorder.setOutputFile(outputFile.getAbsolutePath()); 

This should work as the string parameter is allowed.

+1
source

All Articles