JSFiddle - React, Tailwind, and code Playground

by trkkazulu

HTML

<script src="&lt;script src=&quot;js/libamr-nb.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;js/BitStream.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;js/lib/pcmdata.min.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;js/util.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;js/amr.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;codec.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;js/decoder.js&quot;"></script>
<input type='file' id='file' name='file'>
<button id="do stuff" />
Activate</button>

JavaScript

document.getElementById('file').addEventListener('change', function (evt) {
         handleFileSelect(evt);
	 }, false);



function handleFileSelect(evt,isTypedArray) {
	var f = evt.target.files[0]; // the file object

console.log("this is f " + f);
console.log(f);

	var reader = new FileReader(); 
var ref = reader.readAsArrayBuffer(f);
console.log(ref);
console.log("the reader object is " + reader.length);//why does reader not have a length property?
reader.onload = (function(file) {
	return function(e) {

	var extension = file.name.split(".")[1];

     if(extension === "amr") {
	var stuff = e.target.result;
	console.log("stuff is " + stuff.length + " bytes");
	console.log(stuff);
	

	var jigg = new AMR();
	jigg.benchmark =='true';
	console.log("this is my instance of amr " + jigg); //jigg is defined, it's an instance of amr
var buf = new Uint8Array(128); // this wants a typedArray or unsigned long
var stream = buf;
if(buf.byteLength == 128) {
	alert("Yes, we have a 128 byte buffer");
	} else {
	alert("Nope, it's not 128 bytes");
	}
	var bitstream = new BitStream(stream);
	bitstream.writeBits(12,0xfff);
	bitstream.seekTo(0);
var bs = bitstream.readBits(5,9);
var bs2 = bitstream.readBits(10);
var toproc = reader.readAsArrayBuffer(bitstream);
console.log("did some stuff with bitstream..." + bs);
console.log("did some more stuff with bitstream..." + bs2);

	// let's call some amr functions...
var dcoded = jigg.decode(toproc);//decode() takes a "bitstream" as argument
console.log("this is decoded" + decoded);

//AMR.util.play(dcoded); //this throws an 'undefined' error, indicating that 'dcoded' is undefined. 
	
	} else if(extension == "wav") {
	var data = e.target.result;
	encodeWAV(data);
	} else if(extension =="pcm" && isTypedArray) {
		encodeRawPCM(new Int16Array(e.target.result));
		}
console.log("we return here?");
	}
})
(f);
if(!!isTypedArray) {
	reader.readAsArrayBuffer(stuff);
console.log(stuff + "it is not a typed array");
	return;
	}
// Read the file as a...