Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

play sound javascript

var audio = new Audio("folder_name/audio_file.mp3");
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

play audio with js

function play() {
  var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3');
  audio.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

how to play audio in javascript

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
Comment

how play audio js

let myAudioElement = new Audio('audio.mp3');
myAudioElement.addEventListener("canplaythrough", event => {
  /* the audio is now playable; play it if permissions allow */
  myAudioElement.play();
});
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

js play sound

const sound = require("sound-play");
sound.play("file.mp3");
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript string unique characters 
Javascript :: javascript loop over object entries 
Javascript :: compare and filter two array of object 
Javascript :: javascript is a string numeric 
Javascript :: how to convert array to uppercase in javascript 
Javascript :: window.onload in javascript 
Javascript :: js remove special characters 
Javascript :: first duplicate javascript 
Javascript :: bodyparser purpose 
Javascript :: set time to zero in js date 
Javascript :: js poll dom 
Javascript :: js check window active 
Javascript :: vscode regex replace only group 
Javascript :: js transitions 
Javascript :: how to iterate through dates range in javascript 
Javascript :: javascript get list of files in directory 
Javascript :: socket io client 
Javascript :: comparsion javascript 
Javascript :: js array find string element with max length 
Javascript :: javascript replace all occurrences of string 
Javascript :: javascript remove trailing slash 
Javascript :: css div at bottom of div 
Javascript :: nodejs express hot reload 
Javascript :: javascript dice throw 
Javascript :: check if there is page has scrollbar x js 
Javascript :: react detect enter key 
Javascript :: js invert color 
Javascript :: dart list files in directory 
Javascript :: javascript array filter with multiple id 
Javascript :: promise recursive settimeout 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =