使用以下代码录制 mp3 音频并将其嵌入 html 时,音频不会在浏览器中播放:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("filepath");
mRecorder.prepare();
mRecorder.start();
addRecordingToMediaLibrary();
protected void addRecordingToMediaLibrary() {
ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
//values.put(MediaStore.Audio.Media.TITLE,audiofile.getName());
values.put(MediaColumns.DATE_ADDED, (int) (current / 1000));
values.put(MediaColumns.MIME_TYPE, "audio/3gpp");
values.put(MediaColumns.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
}
但是,如果我将其更改为
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setOutputFile("filepath");
mRecorder.prepare();
mRecorder.start();
addRecordingToMediaLibrary();
声音在浏览器中播放,但干扰很大。
即用 MPEG_4 替换 outputformat,用 AudioEncoder.AAC 替换 AudioEncoder
任何人都可以建议哪种格式最适合嵌入到 android 中的 html 吗?