mirror of https://bitbucket.org/ausocean/av.git
audio-player: formatting
This commit is contained in:
parent
dc72371e74
commit
1865ff9c79
|
@ -23,35 +23,36 @@ LICENSE
|
|||
*/
|
||||
|
||||
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]
|
||||
const reader = new FileReader()
|
||||
|
||||
reader.onload = event => {
|
||||
bytes = new Uint8Array(event.target.result)
|
||||
reader.onload = event => {
|
||||
bytes = new Uint8Array(event.target.result)
|
||||
|
||||
// decode adpcm to pcm
|
||||
var decoded = decode(Array.from(bytes))
|
||||
// decode adpcm to pcm
|
||||
var decoded = decode(Array.from(bytes))
|
||||
|
||||
// convert raw pcm to wav
|
||||
var wav = pcmToWav(decoded, 48000, 1, 16);
|
||||
// convert raw pcm to wav
|
||||
var wav = pcmToWav(decoded, 48000, 1, 16);
|
||||
|
||||
// play wav data in player
|
||||
const blob = new Blob([Uint8Array.from(wav)], {
|
||||
type: 'audio/wav'
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
// play wav data in player
|
||||
const blob = new Blob([Uint8Array.from(wav)], {
|
||||
type: 'audio/wav'
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const audio = document.getElementById('audio');
|
||||
const source = document.getElementById('source');
|
||||
const audio = document.getElementById('audio');
|
||||
const source = document.getElementById('source');
|
||||
|
||||
source.src = url;
|
||||
audio.load();
|
||||
audio.play();
|
||||
}
|
||||
reader.onerror = error => reject(error)
|
||||
reader.readAsArrayBuffer(input)
|
||||
source.src = url;
|
||||
audio.load();
|
||||
audio.play();
|
||||
}
|
||||
reader.onerror = error => reject(error)
|
||||
reader.readAsArrayBuffer(input)
|
||||
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue