-1

Im looking to include some audio into a webpage which will be automatically played on command when some action is done. What is the easiest way to do this without having any physical play/pause buttons on the screen. If so, it it possible to do this just through javascript?

(I'm a beginner so please explain a little more in detail if you can!)

Thanks in Advance!

Hey
  • 87
  • 1
  • 6
  • There has to be event [ like onLoad, onClick,....] to perform some action [ like play/pause ] – a45b Apr 01 '16 at 08:52

4 Answers4

0

Just add an audio tag in your html.. and link to where your audio file is:

<!DOCTYPE html>
<html>
<body>

<audio style="display:none"  autoplay="autoplay" >
  <source src="horse.ogg" type="audio/ogg">

Your browser does not support the audio element.
</audio>

</body>
</html>

use either mp3 or ogg files.

http://www.w3schools.com/html/html5_audio.asp

0

You can look into the HTML 5 audio tag

Omit the controls attribute to remove the physical play/pause. And add autoplay to make the sound play once it's loaded

Igbanam
  • 5,904
  • 5
  • 44
  • 68
0

use html5 audio tag, with autoplay attribute, like this:

https://jsfiddle.net/grassog/odL69p59/

Giuseppe
  • 846
  • 5
  • 10
  • Thanks! But i have one question. This is autoplayed right when the webpage is loaded up. How do i make it so that when i certain value is met this audio will be played. i.e. when plays the audio when the user does a certain action. – Hey Apr 04 '16 at 03:05
  • you use javascript, like this: https://jsfiddle.net/grassog/dLza0n1z/ – Giuseppe Apr 04 '16 at 07:49
0

Use audio tag

 <audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Play audio
</audio>