2018-12-27 15:29:06 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
|
|
var Module = {
|
|
|
|
onRuntimeInitialized: function() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<script src="wrapper.js"></script>
|
|
|
|
<input type="file" id="file" name="file" />
|
|
|
|
<script>
|
|
|
|
function onChange(e) {
|
|
|
|
var file = e.target.files[0];
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var buffer = reader.result;
|
|
|
|
var src = new Uint8Array(buffer);
|
|
|
|
var ptr = Module._malloc(buffer.byteLength);
|
|
|
|
var arr = new Uint8Array(Module.HEAPU8.buffer, ptr, buffer.byteLength);
|
2018-12-29 12:39:49 +00:00
|
|
|
var ctx = new AudioContext();
|
|
|
|
var time = 0;
|
2018-12-27 15:29:06 +00:00
|
|
|
arr.set(src, 0);
|
|
|
|
|
2018-12-29 12:39:49 +00:00
|
|
|
var decoder = new Module.Decoder();
|
|
|
|
decoder.addFragment(ptr, buffer.byteLength);
|
2018-12-27 15:29:06 +00:00
|
|
|
|
2018-12-29 12:39:49 +00:00
|
|
|
while (decoder.hasMore()) {
|
|
|
|
var audio = decoder.decode(1);
|
|
|
|
if (audio === undefined) {
|
|
|
|
if (decoder.hasMore() === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var source = ctx.createBufferSource();
|
|
|
|
source.buffer = audio;
|
|
|
|
source.connect(ctx.destination);
|
|
|
|
source.start(time);
|
|
|
|
time += audio.duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder.delete();
|
2018-12-27 15:29:06 +00:00
|
|
|
}
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
document.getElementById("file").addEventListener("change", onChange, false);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|