I got it to work, createBuffer() method with two arguments was not working on chrome versions anymore, so I had to use decodeAudioData in order to get the buffer source:
// Create AudioContext and buffer source
var audioCtx = new AudioContext();
source = audioCtx.createBufferSource();
// load in an audio track via XHR and decodeAudioData
function getData() {
request = new XMLHttpRequest();
request.open('GET', 'Test.mp3', true);
request.responseType = 'arraybuffer';
request.onload = function() {
var audioData = request.response;
audioCtx.decodeAudioData(audioData, function(buffer) {
myBuffer = buffer;
source.buffer = myBuffer;
analyser = audioCtx.createAnalyser(); // AnalyserNode method
canvas = document.getElementById('CanvasDiv');
canvasContext = canvas.getContext('2d');
source.connect(analyser);
analyser.connect(audioCtx.destination);
frameLooper();
},
function(e){"Error with decoding audio data" + e.err});
}
request.send();
}
function frameLooper(){
ionic.requestAnimationFrame(frameLooper); //You can use window instead of ionic
fbc_array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(fbc_array);
canvasContext.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
canvasContext.fillStyle = '#00CCFF'; // Color of the bars
bars = 100;
for (var i = 0; i < bars; i++) {
bar_x = i * 3;
bar_width = 2;
bar_height = -(fbc_array[i] / 2);
// fillRect( x, y, width, height ) // Explanation of the parameters below
canvasContext.fillRect(bar_x, canvas.height, bar_width, bar_height);
}
}
getData();
var audio = document.getElementById('audioTagId');
Callback = function(){
source.start();
}
document.getElementById("PlayButton").addEventListener("click", Callback);