HTML音频音量调节 [英] Html audio volume adjustment
本文介绍了HTML音频音量调节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将背景音乐自动播放到我的网站,并以10%的音量开始播放.这是我的代码:
I am trying to autoplay a background music to my website and start it playing at 10% volume. This is my code:
<audio id="bgAudio" autoplay src="music.mp3" volume="0.1"></audio>
这对我不起作用.我在互联网上搜索了其他方式,但没有一种有效.谁能帮我吗?
This doesn't work for me. I've searched other ways on the internet but none of them worked. Can anyone help me?
推荐答案
定义音量后,您必须使用Javascript来修改音量,因为音量不是音频标签的有效属性.应该是IMO,但不是.试试这个:
You have to use Javascript to modify the volume after defining it because volume isn't a valid property for the audio tag. It SHOULD be IMO but it isn't. Try this:
<audio autoplay id="bgAudio">
<source src="music.mp3" type="audio/mpeg">
</audio>
<script>
var audio = document.getElementById("bgAudio");
audio.volume = 0.1;
</script>
这篇关于HTML音频音量调节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文