beekeeper beekeeper - 4 years ago 147
HTML Question

Audio is not playing in html

I have music stored in a separate folder that I am trying to play, however the music won't play. Any idea why? All help is appreciated and thanks in advance. Also trying to do the same thing in Jade so if you guys tell me the code for that, it would be great too!

<audio controls>
<source src="./songs/Remember-The-Name.mp3" type="audio/mp3">

Path to html file :


Path to audio file:


Answer Source

You can dynamically generate an audio player, I believe your problem is getting the correct path to your mp3. Use this code and change the src value on line 6. When in doubt, use the absolute path or in your case a relative path of ../songs/Remember-The-Name.mp3

var audio = document.createElement('audio');
var source = document.createElement('source');
var media = document.getElementById('media');
source.setAttribute('src', '');
source.setAttribute('type', 'audio/mpeg');
audio.setAttribute('controls', 'controls');
<section id="media"></section>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download