I\'m trying to encode an mp3 file in base64 format. Then play it through the broswer. It works perfectly on safari and chrome, but not on Firefox.
M
Instead of using readAsBinaryString
then base64 encoding.
use readAsDataURL
which gives you a complete data uri.
<script type="text/javascript">
$(document).ready(function(){
$("#click").click(function(){
var audio = $("input[type='file']").get(0).files[0];
readFile(audio, function(e) {
var result = e.target.result; *// here I get a binary string of my original audio file*
//encodedData = btoa(result); *// encode it to base64*
$("audio").html("<source src=\""+result+"\"/>"); *//add the source to audio*
});
});
});
function readFile(file, onLoadCallback){
var reader = new FileReader();
reader.onload = onLoadCallback;
reader.readAsDataURL(file);
}
</script>
http://jsfiddle.net/Z9pJ7/2/