[英]Android Record Audio issue
I found the code to record audio, but I always get: 我找到了录制音频的代码,但我总是得到:
The method setOutputFile(FileDescriptor) in the type MediaRecorder is not applicable for the arguments (Uri) MediaRecorder类型中的方法setOutputFile(FileDescriptor)不适用于参数(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. 您试图将Uri作为参数传递给不期望的方法。 Just replace
recorder.setOutputFile(target)
with: 只需将
recorder.setOutputFile(target)
替换为:
recorder.setOutputFile(outputFile.getAbsolutePath());
That should work since string parameter is allowed. 这应该工作,因为允许字符串参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.