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
Try this.. It works..
Add ..
to goto previous directory and use type="audio/mpeg"
<body>
<li>
<audio controls>
<source src="../songs/Remember-The-Name.mp3" type="audio/mpeg">
</audio>
</li>
<body>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With