HTML audio tag volume

风流意气都作罢 提交于 2019-11-27 23:19:29

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/33747398/html-audio-tag-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!