开发者

Android Record Audio issue

开发者 https://www.devze.com 2023-01-12 14:34 出处:网络
I found the code to record audio, but I always get: The method setOutputFile(FileDescriptor) in the type M开发者_JAVA技巧ediaRecorder is not applicable for the arguments (Uri)

I found the code to record audio, but I always get:

The method setOutputFile(FileDescriptor) in the type M开发者_JAVA技巧ediaRecorder is not applicable for the arguments (Uri)

So how would I need to describe the filepath 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();


You're trying to pass in an Uri as parameter to the method which doesn't expect that. Just replace recorder.setOutputFile(target) with:

recorder.setOutputFile(outputFile.getAbsolutePath());

That should work since string parameter is allowed.

0

精彩评论

暂无评论...
验证码 换一张
取 消