[英]How to change the Volume of an audio object with html range slider?
hi this is the code I'm using to play a shoutcast cast stream works fine but not able to change the volume is this wrong I'm new at this.嗨,这是我用来播放shoutcast cast流的代码工作正常但无法更改音量这是错误的我是新手。
<script>
function audioobject()
{
var link = new Audio('http://107.155.72.250:8000/;.mp3');
return link;
}
function startradio()
{
audioobject().play();
}
function changevolume(amount)
{
audioobject().setVolume(amount);
}
</script>
<input type="button" id="play" value="Play" onclick="startradio()"/>
<input type="range" id="vol" max="1" min="0" step="0.01" onchange="changevolume(this.value)"/>
The correct method to set the volume is audioobject.volume = VALUE
设置音量的正确方法是audioobject.volume = VALUE
Here's a demo showing a similar setup as you want.这是一个演示,显示了您想要的类似设置。
function changevolume(amount) { var audioobject = document.getElementsByTagName("audio")[0]; audioobject.volume = amount; }
<audio autoplay loop src="https://archive.org/download/animalsounds1/12wolveshowlfar.mp3"></audio> <input type="range" id="vol" max="1" min="0" step="0.01" onchange="changevolume(this.value)" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.