Преглед на файлове

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…
Отказ
Запис