HTML 音频标签音量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33747398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML audio tag volume
提问by Captain Crazy
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.
不用担心合法性。我用于网站的流没有版权,我可以在我的网站上使用它。
回答by sjm
Theres no volume attribute supported by browsers so you must set the volume property in JavaScript
浏览器不支持 volume 属性,所以你必须在 JavaScript 中设置 volume 属性
<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>