diff --git a/cmd/audio-player/index.html b/cmd/audio-player/index.html new file mode 100644 index 00000000..2b813ed4 --- /dev/null +++ b/cmd/audio-player/index.html @@ -0,0 +1,19 @@ + + + + + Audio Player + + + + + + +
+
+ + +
+
+ + \ No newline at end of file diff --git a/cmd/audio-player/main.js b/cmd/audio-player/main.js new file mode 100644 index 00000000..92795a5f --- /dev/null +++ b/cmd/audio-player/main.js @@ -0,0 +1,25 @@ +window.onload = function () { + document.getElementById('input').addEventListener('change', getFile) +} + +function getFile(){ + const input = event.target + if ('files' in input && input.files.length > 0) { + placeFileContent(document.getElementById('content'), input.files[0]) + } +} + +function placeFileContent(target, file) { + readFileContent(file).then(content => { + target.value = content + }).catch(error => console.log(error)) +} + +function readFileContent(file) { + const reader = new FileReader() + return new Promise((resolve, reject) => { + reader.onload = event => resolve(event.target.result) + reader.onerror = error => reject(error) + reader.readAsText(file) + }) +}