2

MediaRecorder 适用于其他版本的 Android,但不适用于 2.3.3:

try {

    MediaRecorder mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    mRecorder.setOutputFile( path + "r_" + FileName );

    int version = android.os.Build.VERSION.SDK_INT;
    Log.d("MP3Downloader", "V: " + version );

    if( version >= 8 ) {
        mRecorder.setAudioEncodingBitRate(16);
        mRecorder.setAudioSamplingRate(44100);
        mRecorder.setAudioChannels(2);
    }

    mRecorder.prepare();
    mRecorder.start();
} catch (Exception e) {
    Log.e("MP3Downloader", "MediaRecorder Failed: " + e.getMessage() );
}

我收到错误 Start Failed: -2147483648 仅在版本 2.3.3 上。我在其他任何地方都没有发现这个问题。

我也试过:

try {

    MediaRecorder mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    FileOutputStream fos = new FileOutputStream( "r_" + FileName);

    mRecorder.setOutputFile( fos.getFD() );



    int version = android.os.Build.VERSION.SDK_INT;
    Log.d("MP3Downloader", "V: " + version );

    if( version >= 8 ) {
        mRecorder.setAudioEncodingBitRate(16);
        mRecorder.setAudioSamplingRate(44100);
        mRecorder.setAudioChannels(1);
    }

    mRecorder.prepare();
    mRecorder.start();
} catch (Exception e) {
    Log.e("MP3Downloader", "MediaRecorder Failed: " + e.getMessage() );
}

但是,我得到异常:“(只读文件系统)”

我有权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
4

1 回答 1

0

尝试将输出格式更改为3gpp.

于 2013-06-10T12:37:14.247 回答