I'm trying to put sounds and music on my program, this code works just fine when I call it as long as I have the archive downloaded on my pc, I want to know if there is a way to play it by a direct link from the Internet or something else so i don't need its archive downloaded.
function music() {
var musics = ["archive.mp3"]
for(var i = 0;i<musics.length;i ){
var music =new Audio(musics[z])
music.play()
}
}
I tried putting URLs on the place of the archive and even other formats but I can't get it to work, when I try to put an URL from YouTube/SoundCloud/some open sound libraries for example and it says no supported source is found.
It seems like the same problem as this guy who didn't get any response:Java - Playing a Sound file from the Internet
CodePudding user response:
You could use the HTML <audio></audio>
tag and add the source of your audio clip, as seen in the example below.
If you want more examples, check out this link
I hope this helps you.
<audio controls autoplay>
<source src="https://assets.mixkit.co/sfx/preview/mixkit-arcade-retro-game-over-213.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>