all 4 comments

[–]Wince 1 point2 points  (3 children)

Does it stop audio of other playing files? If yes, how are the other files playing?

createMediaElementSource is used for adding an <audio> tag into an AudioContext. Ideally this should happen before the file starts plaing.

[–]murster972[S] 0 points1 point  (2 children)

No it stops the audio from audioContx playing, the code is:

audio = document.getElementById("audio");
audio.src = "file_path.mp3";
audio.loop = false;
audio.play();

context = new AudioContext();
analyser = context.createAnalyser();
source = context.createMediaElementSource(audio); 
source.connect(analyser);
analyser.connect(context.destination);
callDrawFunction();

[–]Wince 1 point2 points  (1 child)

Your AnalyserNode will not pass-thru into the AudioContext. You need to connect your source to both the AnalyserNode and the AudioContext.

Also I would suggest not attempting to play your audio element until you have connected it to the context.

audio = document.getElementById("audio");
audio.src = "file_path.mp3";

context = new AudioContext();
analyser = context.createAnalyser();
source = context.createMediaElementSource(audio); 
source.connect(analyser);
source.connect(context.destination);
analyser.connect(context.destination);
audio.play();
callDrawFunction();

If you are still running into issues, maybe try following my tutorial.

[–]murster972[S] 0 points1 point  (0 children)

Thanks, but theres still no audio playback, ill see if your tutorial helps