我通过显示此HTML文档将Twitch流嵌入到WKWebView中:
<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>
按下按钮,我调用toggleAudio()
函数,但该函数仅在第一次调用时才起作用,即我可以取消静音初始流,但在此之后调用该函数无效。如何在每次调用播放器时使该功能静音/取消静音?