Skip to content
Advertisement

Audio player returns Uncaught (In promise): (DOMException) The element has no supported sources

So in my audio player (ka-musicplayer.glitch.me) i saw a flaw that when i played audio by typing the path to an MP3 it returned that. If i predefine the MP3s, it works. Feel free to see the code here.

JavaScript
JavaScript

Advertisement

Answer

After investigating the Audio() constructor, I’ve revised your code.

Firstly, you could write the button element in your HTML and add an event listener rather than generating it dynamically.

JavaScript

Also, at least in the snippet you provided, you’re grabbing the value of the input right away. I’d grab the value when you click the play button:

JavaScript

Notice the "canplaythrough" listener on the player–this delays playing the audio until the audio element and file itself have been completely loaded. You also didn’t need to assign a src to the element; the URL passed into the Audio() constructor is automatically assigned to the source.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement