av/cmd/audio-player/main.js

24 lines
685 B
JavaScript
Raw Normal View History

2019-07-18 06:41:52 +03:00
window.onload = function () {
2019-07-18 09:34:50 +03:00
document.getElementById('input').addEventListener('change', playFile)
2019-07-18 06:41:52 +03:00
}
2019-07-18 09:34:50 +03:00
function playFile() {
const input = event.target.files[0]
2019-07-18 06:41:52 +03:00
2019-07-18 09:34:50 +03:00
const reader = new FileReader()
reader.onload = event => playData(event.target.result) // desired file content
reader.onerror = error => reject(error)
reader.readAsArrayBuffer(input) // you could also read images and other binaries
2019-07-18 06:41:52 +03:00
}
2019-07-18 09:34:50 +03:00
function playData(array){
var data = new Uint8Array(array)
console.log("playing file")
var player = new PCMPlayer({
encoding: '16bitInt',
channels: 1,
sampleRate: 48000,
flushingTime: 2000
});
player.feed(data)
}