2011-09-09 101 views
2

我如何將音頻文件錄製爲.m4a格式。如何將音頻文件錄製爲.m4a格式?

我使用下面的代碼:

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

感謝..

回答

6

在這裏你設置你的例子輸出格式:

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 

here是的列表可用的輸出格式包括:

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 

和這裏的more information有關支持的格式,它看起來像它支持MPEG-4音頻(M4A),所以我假設,你應該選擇MediaRecorder.OutputFormat.MPEG_4

相關問題