简体   繁体   English

使用JS设置音频元素音量

[英]Setting audio element volume with JS

I'm trying to set the volume of my audio element using JavaScript but I can't get it to actually change. 我正在尝试使用JavaScript设置音频元素的音量,但我无法真正更改它。 I'll console log audio.volume and it shows that it's set to whatever I set it to in the JS but doesn't actually affect the volume. 我将控制台audio.volume日志,它显示它已设置为我在JS中设置的值,但实际上并没有影响音量。 (Trying to set it to 0 just to see if it mutes) (尝试将其设置为0只是为了查看它是否静音)

Here is my Code 这是我的代码

HTML HTML

<audio id="audio" v-if="image.play == true" loop autoplay>
   <source v-bind:src="image.audio" type="audio/wav">
</audio>

JS JS

const audio = document.querySelector('audio');
audio.volume = 0;
<script>    
    var audio = document.getElementById("audio");
    audio.volume = 0.2;
</script>

You can change the volume from 0.0 (silenced) to 1.0 (loud) with HTML5. 您可以使用HTML5将音量从0.0(静音)更改为1.0(静音)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM