audio-player: formatting

This commit is contained in:
Trek H 2019-08-11 16:54:30 +09:30
parent dc72371e74
commit 1865ff9c79
1 changed files with 24 additions and 23 deletions

View File

@ -23,35 +23,36 @@ LICENSE
*/ */
window.onload = function () { window.onload = function () {
document.getElementById('input').addEventListener('change', processData)
document.getElementById('input').addEventListener('change', function () { }
const input = event.target.files[0]
const reader = new FileReader() function processData() {
const input = event.target.files[0]
reader.onload = event => { const reader = new FileReader()
bytes = new Uint8Array(event.target.result)
reader.onload = event => {
// decode adpcm to pcm bytes = new Uint8Array(event.target.result)
var decoded = decode(Array.from(bytes))
// decode adpcm to pcm
// convert raw pcm to wav var decoded = decode(Array.from(bytes))
var wav = pcmToWav(decoded, 48000, 1, 16);
// convert raw pcm to wav
// play wav data in player var wav = pcmToWav(decoded, 48000, 1, 16);
const blob = new Blob([Uint8Array.from(wav)], {
type: 'audio/wav' // play wav data in player
}); const blob = new Blob([Uint8Array.from(wav)], {
const url = URL.createObjectURL(blob); type: 'audio/wav'
});
const audio = document.getElementById('audio'); const url = URL.createObjectURL(blob);
const source = document.getElementById('source');
const audio = document.getElementById('audio');
source.src = url; const source = document.getElementById('source');
audio.load();
audio.play(); source.src = url;
} audio.load();
reader.onerror = error => reject(error) audio.play();
reader.readAsArrayBuffer(input) }
reader.onerror = error => reject(error)
}) reader.readAsArrayBuffer(input)
} }