1

I use the code below to record an audio file and encode it in Base64.

To record the audio:

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();

To encode to Base64:

 byte[] bytes = new byte[0];
    try {
        bytes = IOUtil.readFile(mFileName);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String encoded = new String(Base64.encodeBytes(bytes));

The returned String, if decoded online (e.g., http://www.opinionatedgeek.com/DotNet/Tools/Base64Decode/), plays well when downloaded in .bin format and played in vlc. However, the same String won't be played in 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>

I have searched, but I couldn't find the answer. Does anyone know where the problem is?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Student22b
  • 79
  • 3
  • 13
  • http://iandevlin.com/html5/data-uri/audio.php it's certainly possible, but maybe it's 3gpp/amr? http://stackoverflow.com/questions/27915454/how-to-play-amr-file-in-html-or-website edit: http://www.leanbackplayer.com/test/h5mt.html also indicates in all browsers I've tested that 3gpp is not a file that works as html5 audio. – zapl Oct 04 '15 at 22:30

0 Answers0