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 update the object value of any array key based on value 
Javascript :: javascript get first character of string 
Javascript :: store array in localstorage 
Javascript :: react redux wait for props 
Javascript :: jquery uncheck all other checkboxes when one is checked 
Javascript :: ng build staging 
Javascript :: ajax image post ekleme 
Javascript :: money separator in javascript 
Javascript :: on uncheck checkbox hide button jquery 
Javascript :: javascript compare two objects 
Javascript :: javascript not empty array not string 
Javascript :: javascript password validation regex test 
Javascript :: p5.js create button 
Javascript :: JavaScript Using a Temporary Variable 
Javascript :: linking javascript to Flask html 
Javascript :: javascript last element in array 
Javascript :: js first letter capital 
Javascript :: ReferenceError: http Server is not defined 
Javascript :: execute JS code after pressing space bar 
Javascript :: drupal 8 get node from form 
Javascript :: React Redux reducer combineReducers exemple 
Javascript :: add leading spaced in string javascript 
Javascript :: docker react js 
Javascript :: check if a variable is a number in javascript 
Javascript :: get current date 
Javascript :: js every x seconds 
Javascript :: js encode to & 
Javascript :: chartjs how to disable hover lable 
Javascript :: loop key in object 
Javascript :: how to loop and add number in fuction for javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =