It's pretty simple to get started really:
function playSound(url) {
var a = new Audio(url);
a.play();
}
Use that as whatever event handler you want for your application. Of course, I'd hope you'd want to do more than just play (for example, maybe pause would be good too?), but it's a start.
Answer from nickf on Stack Overflowaudio - Reference URL with JavaScript to play sound? - Stack Overflow
Freesound - Forums - Freesound Project - Link to sound
Play mp3 via url only
How to create a file online for an mp3, that is a URL ending in .mp3?
How to download audio from link?
How long do audio URLs last?
How do I share audio files as a link?
Videos
It's pretty simple to get started really:
function playSound(url) {
var a = new Audio(url);
a.play();
}
Use that as whatever event handler you want for your application. Of course, I'd hope you'd want to do more than just play (for example, maybe pause would be good too?), but it's a start.
let sound = new Audio("http://sound.com/mySound.mp3");
//on play event:
sound.onplay = () => {
};
//on pause event:
sound.onpause = () => {
};
//on end event:
sound.onended = () => {
};
//play:
sound.play();
//pause:
sound.pause();
//stop:
sound.pause();
sound.currentTime = 0;
The lesson "Learn Basic String and Array Methods by Building a Music Player" uses audio files such as "https://cdn.freecodecamp.org/curriculum/js-music-player/scratching-the-surface.mp3". I'm trying to upload my own audio file somewhere on the internet so that I can use it in my code just like this, but I just can't figure out how to. Any help?