var audio = new Audio("folder_name/audio_file.mp3");
audio.play();
<button onclick="playSound()">Play</button>
<script>
let playSound = () => new Audio("src.mp3").play();
</scirpt>
<script>
function play() {
var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/examples/t-rex-roar.mp3');
audio.play();
}
</script>
<button onclick-"play();">PLAY MY AUDIO</button>
var audio = new Audio('audio_file.mp3');
audio.play();
var bMusic = new Audio('welcome1.mp3')
bMusic.play()
//play audio with from html audio element:
document.getElementById('myAudioTagID').play();
//play audio with out html audio tag
var myAudio = new Audio('my_great_song.mp3');
myAudio.play();
function play() {
var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3');
audio.play();
}
<!doctype html>
<html>
<head>
<title>Audio</title>
</head>
<body>
<script>
function play() {
var audio = document.getElementById("audio");
audio.play();
}
</script>
<input type="button" value="PLAY" onclick="play()">
<audio id="audio" src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"></audio>
</body>
</html>
var audio = new Audio("folder_name/audio_file.mp3");
audio.play(); // start playing audio
audio.pause(); // pause audio
audio.currentTime = 0; // makes sure audio is played from the beginning when resumed
let myAudioElement = new Audio('audio.mp3');
myAudioElement.addEventListener("canplaythrough", event => {
/* the audio is now playable; play it if permissions allow */
myAudioElement.play();
});
JavaScript
function playAudio(url) {
new Audio(url).play();
}
HTML
<img src="image.png" onclick="playAudio('mysound.mp3')">
Supported in most modern browsers and easy to embed into HTML elements.
const sound = require("sound-play");
sound.play("file.mp3");