无法在嵌入的 Twitch 元素中禁用 javascript 中的自动播放。我该如何解决?

Can't disable autoplay in javascript in an embedded Twitch element. How do I fix this?

这是我现在 运行 的代码:

<!doctype html>

<html lang="DE">
<head>
<meta charset="utf-8">

<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="xPlayzTV">

</head>

<body>
<!-- Add a placeholder for the Twitch embed -->
<div id="twitch-embed"></div>

<!-- Load the Twitch embed script -->
<script src="https://embed.twitch.tv/embed/v1.js"></script>

<!--
  Create a Twitch.Embed object that will render
  within the "twitch-embed" root element.
-->
<script type="text/javascript">
  var embed = new Twitch.Embed("twitch-embed", {
    width: "480",
    height: "270",
theme: "dark",
    channel: "onyxtao",
    layout: "video",
    autoplay: "false",
muted: "true",
    // only needed if your site is also embedded on embed.example.com and othersite.example.com 
    parent: ["www.onyx-warframe.com"]
  });

  embed.addEventListener(Twitch.Embed.VIDEO_READY, () => {
    var player = embed.getPlayer();
    player.play();
  });

如您所见,我有一行说 autoplay 设置为 false。尽管在 Twitch 的嵌入指南中列出 boolean,但它似乎不起作用。我也试过用 0 替换它,并完全删除 autoplay 行,但都没有用。有没有人对此有其他解决方案,最好有解释,以便我知道问题出在哪里?

您将变量转换为字符串而不是布尔值或整数导致意外行为

      var embed = new Twitch.Embed("twitch-embed", {
        width: "480",
        height: "270",
        theme: "dark",
        channel: "onyxtao",
        layout: "video",
        autoplay: "false",
        muted: "true",
        // only needed if your site is also embedded on embed.example.com and othersite.example.com 
        parent: ["www.onyx-warframe.com"]
      });

应该是

      var embed = new Twitch.Embed("twitch-embed", {
        width: 480,
        height: 270,
        theme: "dark",
        channel: "onyxtao",
        layout: "video",
        autoplay: false,
        muted: true,
        parent: ["www.onyx-warframe.com"]
      });

因此您的“假”被视为“真实”

编辑:

您还需要删除

      embed.addEventListener(Twitch.Embed.VIDEO_READY, () => {
        var player = embed.getPlayer();
        player.play();
      });

因为这会在播放器完成加载时触发播放功能