Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML audio tag volume

I embedded a background audio into my website which autoplays on visit.

The source of the audio is a online stream hotlink.

<audio autoplay>       <source src="http://lel.com/link/to/stream.m3u">     </audio> 

I already managed to do that and it's working well.

Now I want to turn down the volume of the stream because the audio should just stay in the background and entertain the visitors instead of giving them ear cancer due to loudness.

I already searched the forums but I always found solutions for turning the volume of a video.

I also searched for the parameters of the audio tag but there seems no volume parameter for the audio tag.

Don't worry about legalities. The stream I use for the website has no copyright and I am permitted to use it on my website.

like image 566
Captain Crazy Avatar asked Nov 17 '15 00:11

Captain Crazy


People also ask

What is the HTML tag for audio?

The <audio> tag is used to embed sound content in a document, such as music or other audio streams.

How do I change the size of an audio file in HTML?

<audio> can be styled as any other html element. To increase the width just use the css property width .

How do I show audio controls in HTML?

HTML Audio - How It WorksThe controls attribute adds audio controls, like play, pause, and volume. The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.


1 Answers

Theres no volume attribute supported by browsers so you must set the volume property in JavaScript

<audio autoplay id="myaudio">   <source src="http://lel.com/link/to/stream.m3u"> </audio>  <script>   var audio = document.getElementById("myaudio");   audio.volume = 0.2; </script> 

See http://jsfiddle.net/sjmcpherso/6r1emoxq/

like image 183
sjm Avatar answered Sep 26 '22 00:09

sjm