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?