4

I'm embedding a Twitch stream into my WKWebView by displaying this HTML document:

<html>
  <body style="margin:0;">
    <div id="twitch-embed"></div>

    <script src="https://embed.twitch.tv/embed/v1.js"></script>

    <script type="text/javascript">
      var embed = new Twitch.Embed("twitch-embed", {
        width: "100%",
        height: "100%",
        channel: "esl_sc2",
        layout: "video",
      });

      function toggleAudio() {
        var player = embed.getPlayer();
        var isMuted = player.getMuted()
        player.setMuted(!isMuted)
      }
    </script>
  </body>
</html>

On a button press I call the toggleAudio() function, however the function only works the first time it is called, i.e. I can unmute the initial stream but after that calling the function has no effect. How do I make the function mute/unmute the player each time it is called?

Nibr
  • 187
  • 1
  • 9
  • 1
    My testing indicates that setMuted(false) and setMuted() both correctly unmute the stream, but setMuted(true) does nothing. Not really sure why. – JBC Mar 02 '18 at 17:13
  • I had the same experience as JBC during my testing. I ended up using .setVolume(0) which results in the player being muted. – Ryan Macdonald Dec 30 '18 at 02:00
  • That works reasonably well but has the problem that unmuting with the actual unmute button will not reset the volume to the old value. – Nibr Dec 30 '18 at 11:30

0 Answers0