dimanche 27 novembre 2016

Web Audio AnalyserNode returns empty data

HTML:

<audio id="myAudio" src="song.mp3" oncanplay="done(this)"></audio>

JS:

function done(audio) {

    var ctx = new AudioContext();

    var audioSrc = ctx.createMediaElementSource(audio);
    var analyser = ctx.createAnalyser();

    audioSrc.connect(analyser);
    audioSrc.connect(ctx.destination);

    var array = new Uint8Array(analyser.frequencyBinCount);
    analyser.getByteFrequencyData(array);

    console.log(array);

}

All that is written to the console is an array of all zeroes. Anybody know what's wrong with this code?




Aucun commentaire:

Enregistrer un commentaire