Question

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)"/>
Was it helpful?

Solution

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.org/download/animalsounds1/12wolveshowlfar.mp3"></audio>

<input type="range" id="vol" max="1" min="0" step="0.01" onchange="changevolume(this.value)" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top