【问题标题】:Android Record Audio issueAndroid 录制音频问题
【发布时间】:2010-08-23 19:57:47
【问题描述】:

我找到了录制音频的代码,但我总是得到:

MediaRecorder 类型中的方法 setOutputFile(FileDescriptor) 不适用于参数 (Uri)

那么我需要如何描述它工作的文件路径呢?

// 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();

【问题讨论】:

    标签: android android-audiomanager


    【解决方案1】:

    您正在尝试将 Uri 作为参数传递给不期望的方法。 只需将recorder.setOutputFile(target) 替换为:

    recorder.setOutputFile(outputFile.getAbsolutePath());
    

    这应该可以工作,因为允许使用字符串参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多