htmlbase64html5-audiowav

How to add audio in html5 with base64 encoding


I have a string that is audio encoded in base64 and in wav format (I have adata link - {{vm.record}}).

I need to add an audio player in a widget which is written in js + html.

I don't understand why this didn't work. Do I need to write something in js to make this work? Where I can specify encoding ?

<audio 
    controls 
    src={{vm.record}} type="audio/wav; base64" autobuffer="autobuffer" autoplay="autoplay">
    Your browser does not support the <code>audio</code> element.
</audio>

I know that "type="audio/wav; base64" is wrong.

I also tried this, but it didn't work:

<audio controls src="data:audio/ogg;base64,T2dnUwACAAAAAAAAAAAfm5nB6slBlZ3Fcha363d5ut7u3ni1rLoPf728l3KcK"/>

Solution

  • You can have an HTML5 audio tag in base64 encoding as so:

    <audio controls autoplay loop src="data:audio/ogg;base64,BASE64CODE" />
    

    No need for a type! :)