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!

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




Path to html file :


/User/Desktop/music-app/views/test.html


Path to audio file:


/User/Desktop/music-app/songs/Remember-The-Name.mp3

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');
media.appendChild(audio);
audio.appendChild(source);
source.setAttribute('src', 'https://glpro.s3.amazonaws.com/_util/smpte/111.mp3');
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