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 :: how to sort array by dates 
Javascript :: nestjs change httpcode inside function 
Javascript :: binary agents freecodecamp 
Javascript :: js message timeout 
Javascript :: check palindrome javascript 
Javascript :: lodash remove undefined values from object 
Javascript :: jquery version how 
Javascript :: print table javascript 
Javascript :: how to sort an array of objects by a property value in javascript 
Javascript :: start angular app server 
Javascript :: js spread exclude property 
Javascript :: compare two arrays and make sure there are no duplicates js 
Javascript :: how to go to next line in javascript 
Javascript :: Array.include is not a function javascript error help 
Javascript :: js ajax receive html 
Javascript :: extract urls from string javascript 
Javascript :: eslintrc ignore rule 
Javascript :: sort divs alphabetically jquery 
Javascript :: sum of array elements in javascript 
Javascript :: datatables dynamically hide columns 
Javascript :: disable eslint specific rule 
Javascript :: joi string custom validation fuction 
Javascript :: javascript date time 
Javascript :: loop in react depending on number 
Javascript :: angular 9 dockerfile 
Javascript :: play audio with js 
Javascript :: npm js-cookie 
Javascript :: print placeholder value javascript 
Javascript :: unload in jquery 
Javascript :: On click, disable button 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =