1,報(bào)錯(cuò):
start failed: -22
出現(xiàn)這個(gè)問(wèn)題有梆,一直搜索百度google赁炎,還是找不到對(duì)應(yīng)的信息醉箕。后面再看到采樣率的問(wèn)題上,看到采樣率在特定機(jī)型上是支持和不支持之分徙垫。
然后查了下自己手上的三星采樣率讥裤,支持的是8000。于是改了后就可以了姻报。
改前:
File file = new File(context.getExternalCacheDir(), "record-cache");
mRecorder = new MediaRecorder();
// 如果不存在要?jiǎng)?chuàng)建
if (!file.exists()) file.mkdirs();
mPath = file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".amr";
//設(shè)置音源為麥克風(fēng)
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//設(shè)置封裝格式
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
//設(shè)置所錄制的聲音的采樣率
mRecorder.setAudioSamplingRate(16000);
//設(shè)置編碼格式
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//輸出文件
mRecorder.setOutputFile(mPath);
try {
mRecorder.prepare();
mStartTime = System.currentTimeMillis();
} catch (IOException e) {
Tools.SystemOut.out("錄音失敗");
}
//錄音
mRecorder.start();
改后:
File file = new File(context.getExternalCacheDir(), "record-cache");
mRecorder = new MediaRecorder();
// 如果不存在要?jiǎng)?chuàng)建
if (!file.exists()) file.mkdirs();
mPath = file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".amr";
//設(shè)置音源為麥克風(fēng)
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//設(shè)置封裝格式
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
//設(shè)置所錄制的聲音的采樣率
mRecorder.setAudioSamplingRate(8000);
//設(shè)置編碼格式
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//輸出文件
mRecorder.setOutputFile(mPath);
try {
mRecorder.prepare();
mStartTime = System.currentTimeMillis();
} catch (IOException e) {
Tools.SystemOut.out("錄音失敗");
}
//錄音
mRecorder.start();
最后:
運(yùn)行以后就不會(huì)報(bào)錯(cuò)了己英。