最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change the Volume of an audio object with html range slider? - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

The 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)" />

发布评论

评论列表(0)

  1. 暂无评论