how can i record audio file as .m4a format?

梦想与她 提交于 2019-12-10 10:28:08

问题


how can i record audio file as .m4a format.

i am using the code below:

public void startRecording() throws IOException {

    recorder = new MediaRecorder();

    path = "/sdcard/pithysongs_" + System.currentTimeMillis() + ".m4a";

    String state = android.os.Environment.getExternalStorageState();

    if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
        throw new IOException("SD Card is not mounted.  It is " + state
                + ".");
    }

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();
    }

thanks..


回答1:


Here's where you set the output format in your example:

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

and here is a list of the available output formats which include:

AMR_WB  AMR WB file format
DEFAULT     
MPEG_4  MPEG4 media file format
RAW_AMR     AMR NB file format
THREE_GPP   3GPP media file format

and here's more information about supported formats which looks like it supports MPEG-4 audio (m4a) so I assume that you should choose MediaRecorder.OutputFormat.MPEG_4



来源:https://stackoverflow.com/questions/7357826/how-can-i-record-audio-file-as-m4a-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!