admin管理员组文章数量:1433520
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.
<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)"/>
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.
<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)"/>
Share
Improve this question
edited Jan 12, 2021 at 12:34
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Apr 16, 2014 at 0:24
manitejamaniteja
7172 gold badges16 silver badges32 bronze badges
1 Answer
Reset to default 5The correct method to set the volume is 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/download/animalsounds1/12wolveshowlfar.mp3"></audio>
<input type="range" id="vol" max="1" min="0" step="0.01" onchange="changevolume(this.value)" />
本文标签: javascriptHow to change the Volume of an audio object with html range sliderStack Overflow
版权声明:本文标题:javascript - How to change the Volume of an audio object with html range slider? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745580563a2664596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论