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() );
}
我在版本2.3.3上收到错误开始失败:-2147483648。我没有发现其他任何地方都有这个问题。
我也尝试过:
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" />
答案 0 :(得分:0)
使用3gpp更改输出格式。