【问题标题】:Android: recording audio using MediaRecorder - file doesnt playAndroid:使用 MediaRecorder 录制音频 - 文件不播放
【发布时间】:2017-11-10 00:47:55
【问题描述】:

我已经使用 MediaRecorder 直接从 Google 实现了示例代码

我还添加了一些属性并将文件类型设置为“.mp3”(我知道它不会创建真正的 mp3,但“.3gp”对我来说也没有意义,我正在录制音频而不是视频.. )

现在我的问题是,如果我想播放文件,它什么也不做(0:00 秒)。我检查了文件的属性,它填满了存储空间。

补充:

无论如何,我想在录制时实现视觉反馈。 Horizon 似乎是唯一好看的库。但是使用 Horizo​​n,您必须使用 Audiorecorder 的缓冲区来提供它,而 MediaRecoder 则无法做到这一点。有谁知道一个好看的库,可以用 MediaRecorder 可视化当前录制的音频?

非常感谢

private void startRecording() {
    if(this.mRecorder != null)
        return;

    String fileToWrite = this.ProjectDirPath + File.separator + GetToday() + this.fileTpye;

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setOutputFile(fileToWrite);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
    mRecorder.setAudioSamplingRate(16000);
    mRecorder.setAudioEncodingBitRate(44100);
    mRecorder.setAudioChannels(1);

    try {
        mRecorder.prepare();
    }catch (IOException e) {
        Log.e("startRecording()", "prepare() failed");
    }

    initRecorder();
    mRecorder.start();
    isRecording = true;
}



private void stopRecording() {
    if(this.mRecorder == null)
        return;
    else{
        try{
            mRecorder.stop();
            mRecorder.release();
            mRecorder = null;
            isRecording = false;
            this.updateListView();
        } catch(Exception e){
            mRecorder = null;
            isRecording = false;
        }
    }
}

public static String GetToday(){
    Date presentTime_Date = Calendar.getInstance().getTime();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return dateFormat.format(presentTime_Date);
}

权限在清单和运行时设置。

【问题讨论】:

    标签: android audio mediarecorder


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多