我使用下面的代码录制音频文件并在Base64中对其进行编码。
录制音频:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.prepare();
mRecorder.start();
要编码为Base64:
byte[] bytes = new byte[0];
try {
bytes = IOUtil.readFile(mFileName);
} catch (IOException e) {
e.printStackTrace();
}
String encoded = new String(Base64.encodeBytes(bytes));
如果以.bin格式下载并在vlc中播放,则返回的字符串,如果在线解码(例如,http://www.opinionatedgeek.com/DotNet/Tools/Base64Decode/),则播放效果良好。但是,相同的字符串不会在HTML5中播放:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Providing HTML5 audio with a base64 encoded Data URI as source</title>
<meta charset="utf-8">
</head>
<body>
<audio controls="controls" autobuffer="autobuffer" autoplay="autoplay">
<source src="data:audio/3gpp;base64,<DecodedString>">
</audio>
</body>
</html>
我搜索过,但我找不到答案。有谁知道问题在哪里?