Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

play sound javascript

var audio = new Audio("folder_name/audio_file.mp3");
audio.play();
Comment

javascript play sound onclick

var audio = new Audio("soundfile.wav");

document.onclick = function() {
  audio.play();
}
Comment

play audio on click javascript

<button onclick="playSound()">Play</button>

<script>
let playSound = () => new Audio("src.mp3").play();
</scirpt>
Comment

play sound in javascript

<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>
Comment

play audio in javascript

var audio = new Audio('audio_file.mp3');
audio.play();
Comment

play audio javascript


var bMusic = new Audio('welcome1.mp3')
	bMusic.play()
Comment

javascript play audio

//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();
Comment

javascript audio play on click

<!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>
Comment

Javascript Audio Play on click


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.
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery not equal 
Javascript :: or operator js 
Javascript :: create array of numbers js 
Javascript :: javascript get object where 
Javascript :: legend on click use default chartjs 
Javascript :: kick members node js 
Javascript :: eval set global scope 
Javascript :: reduce to calculate sum react 
Javascript :: check if array exists in another array javascript 
Javascript :: name arrow function 
Javascript :: javascript for loop[ 
Javascript :: add a socket to a room in socket.io 
Javascript :: get size of array in bytes javascript 
Javascript :: javascript array to string without commas 
Javascript :: submit form with ajax 
Javascript :: mangoosejs 
Javascript :: javascript set color in hex 
Javascript :: get selected value in dropdown 
Javascript :: update query in mongoose 
Javascript :: js reduce method 
Javascript :: express js sample project 
Javascript :: how to get the difference between two arrays in javascript 
Javascript :: pass array from controller to javascript blade 
Javascript :: multipart/form-data ajax jquery 
Javascript :: javascript get selected text 
Javascript :: React native calender date picker 
Javascript :: javascript classlist to array 
Javascript :: find duplicate element on array 
Javascript :: is promise 
Javascript :: stripe angular 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =