瀏覽代碼

added support for multiple file uploads

dds
Matt Bradshaw 6 年之前
父節點
當前提交
4fcb6c2923
共有 2 個檔案被更改,包括 17 行新增9 行删除
  1. +2
    -2
      extras/wav2sketch/wav2sketch.html
  2. +15
    -7
      extras/wav2sketch/wav2sketch.js

+ 2
- 2
extras/wav2sketch/wav2sketch.html 查看文件

@@ -6,9 +6,9 @@
<h1>Teensy Audio Wav2Sketch Utility</h1>
<p>Upload an audio file to convert it into Teensy audio format.</p>
<form>
<input id="audioFileChooser" name="audioFileChooser" type="file" accept="audio/*">
<input id="audioFileChooser" name="audioFileChooser" type="file" accept="audio/*" multiple>
<div id="outputFileHolder"></div>
</form>
<script type="text/javascript" src="wav2sketch.js"></script>
</body>
</html>
</html>

+ 15
- 7
extras/wav2sketch/wav2sketch.js 查看文件

@@ -1,15 +1,22 @@
/*
TODO
multiple files
stereo
non-44100 sample rates
*/

var audioFileChooser = document.getElementById('audioFileChooser');

audioFileChooser.addEventListener('change', readFile);

function readFile() {
// TODO: deal with multiple files
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(audioFileChooser.files[0]);
window.testFile = audioFileChooser;
fileReader.addEventListener('load', function(ev) {
processFile(ev.target.result, audioFileChooser.files[0].name);
});
for(var i = 0; i < audioFileChooser.files.length; i++) {
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(audioFileChooser.files[i]);
fileReader.addEventListener('load', function(fileName, ev) {
processFile(ev.target.result, fileName);
}.bind(null, audioFileChooser.files[i].name));
}
}

function processFile(file, fileName) {
@@ -50,6 +57,7 @@ function processFile(file, fileName) {
outputFileHolder.appendChild(downloadLink1);
outputFileHolder.appendChild(document.createElement('br'));
outputFileHolder.appendChild(downloadLink2);
outputFileHolder.appendChild(document.createElement('br'));
});
}


Loading…
取消
儲存