✅ – BIOLOGY SCIENCE – 14-32 Oct 5

[Audio API] Audio doesn't play when I use createMediaElementSource on an audio element. (more info + code inside thread)
5 Replies
RelativPerspektiv
function start()
{
const audio = new Audio();

const
audioContext = new AudioContext(),
audioAnalyser = new AnalyserNode(audioContext);

audioContext.createMediaElementSource(audio).connect(audioAnalyser); // this line

audio.src = 'E:/Music/Fighter.mp3';

audio.play();
};

start();
function start()
{
const audio = new Audio();

const
audioContext = new AudioContext(),
audioAnalyser = new AnalyserNode(audioContext);

audioContext.createMediaElementSource(audio).connect(audioAnalyser); // this line

audio.src = 'E:/Music/Fighter.mp3';

audio.play();
};

start();
i just have this script inside the head of an html file (no other contents in the html) there is apparently no playback of the audio. but if i remove the marked line, the audio plays. and no errors in the console as well. any idea whats happening ? and a fix (without removing the marked line) ?
rubberduckies
rubberduckies2y ago
you're only piping it to the analyser, not to the speakers after this: audioContext.createMediaElementSource(audio).connect(audioAnalyser); try: audioAnalizer.connect(audioContext.destination)
RelativPerspektiv
oh ok lemme try cool, it works @rubberduckies thanks 🙂
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1027226672153514084
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1027226672153514084 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26