javascripthtml5-videotwitch

How do I adjust a twitch player's volume with Javascript?


I found the following example of adjusting the volume of an embedded twitch player, but this was in the context of creating one's own web page and and then adjusting the instance volume from there. How do I select a player already on screen & set it's volume from console?

<script src= "http://player.twitch.tv/js/embed/v2.js"></script>
<div id="{PLAYER_DIV_ID}"></div>
<script type="text/javascript">
    var options = {
        width: '100%',
        height: 480,
        channel: "channel", 
        //video: "{VIDEO_ID}"       
    };
    var player = new Twitch.Player("{PLAYER_DIV_ID}", options);
    player.setVolume(0.3);
</script>

Solution

  • For me, I was only looking to adjust the volume of Twitch player videos on my client side / using a bookmarklet. This will also work in the Developer Tools console if you prefer to play around there.

    This answer assumes you already know a bit about how to locate and select the element, and will break / require an update if and when Twitch changes it's classes or html.

    I hope this helps - happy lurking friends!

    volumeControl = document.body.querySelector(".player-video video");
    
    volumeControl.volume = 0.01;