【问题标题】:Javascript - How to unmute youtube videos in iframeJavascript - 如何在 iframe 中取消静音 youtube 视频
【发布时间】:2020-07-01 23:25:47
【问题描述】:

我的 youtube 视频在 iframe 中完美显示,但没有声音。下面是我的代码。

if (slideType === "youtube") {
    switch (control) {
      case "play":
        postMessageToPlayer(player, {
          "event": "command",
          "func": "mute"
        });
        postMessageToPlayer(player, {
          "event": "command",
          "func": "playVideo" 
        });
        break;
      case "pause":
        postMessageToPlayer(player, {
          "event": "command",
          "func": "pauseVideo"
        });
        break;
    }
  }

// POST commands to YouTube API
function postMessageToPlayer(player, command){
  if (player == null || command == null) return;
  player.contentWindow.postMessage(JSON.stringify(command), "*");
}

如果我删除了视频不播放的静音部分,则从上述部分。如果我发送取消静音而不是静音,视频仍然无法播放。如何让正在播放的视频有声音?

【问题讨论】:

    标签: javascript html video iframe youtube-api


    【解决方案1】:

    除非您的iframe 标签中有allow="autoplay;",否则您将无法unmute 视频。添加此属性,进一步的unMute 功能将起作用。

    【讨论】:

      【解决方案2】:

      通常,您只需单击静音按钮即可取消静音。

      【讨论】:

      • 没有静音按钮
      • 可以加张图片吗?
      猜你喜欢
      • 1970-01-01
      • 2019-07-12
      • 2015-11-17
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2012-02-10
      相关资源
      最近更新 更多