【问题标题】:Embedded youtube video loading but not playing嵌入的 youtube 视频加载但不播放
【发布时间】:2021-01-07 08:24:54
【问题描述】:

我正在开发一个 Shopify 网站,我想嵌入一个 Yt 视频。我选择自己做。

按照 Youtube API 和相关 (https://developers.google.com/youtube/iframe_api_reference?hl=it#Getting_Started) 我设法基本上复制并粘贴了以下代码:

<div id="ytplayer"></div>

<script>
  // Load the IFrame Player API code asynchronously.
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/player_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  // Replace the 'ytplayer' element with an <iframe> and
  // YouTube player after the API code downloads.
  var player;
  function onYouTubePlayerAPIReady() {
    player = new YT.Player('ytplayer', {
      height: '360',
      width: '640',
      videoId: '{{ section.settings.id }}'
    });
  }
</script>

当然 {{ section.settings.id }} 工作正常,实际上视频播放器已加载,但当按下播放视频时,我会提示“出现错误。稍后再试。”事物。所以我想这可能是因为该网站受密码保护,但后来我尝试了一个实时网站(Tryit Editor),它也不起作用。

感谢任何帮助,非常感谢!

编辑:这是工作示例:https://jsfiddle.net/kb06t7rh/

【问题讨论】:

  • 您需要提供工作演示以获得更好的帮助。
  • @Onkar 完成,请看一下
  • 打开小提琴链接,一切都对我有用
  • @NicoHaase 我在 chrome 中,但它对我不起作用......有什么想法吗?
  • 我在最新的火狐版本和最新的Chrome版本都试过了,两种浏览器都可以开始播放视频

标签: javascript html youtube-api shopify


【解决方案1】:
<div id="ytplayer"></div>

<script>
  // Load the IFrame Player API code asynchronously.
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/player_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  // Replace the 'ytplayer' element with an <iframe> and
  // YouTube player after the API code downloads.
  var player;
  function onYouTubePlayerAPIReady() {
    player = new YT.Player('ytplayer', {
      height: '360',
      width: '640',
      videoId: '{{ section.settings.video_url.id }}'
    });
  }
</script>

视频选项的 Shopify 架构

{
    "type": "video_url",
    "id": "video_url",
    "label": "video_url",
    "accept": ["youtube"]
}

【讨论】:

  • 您的答案首先从语法角度(架构)是不正确的,它没有回答我的问题:视频加载但为什么不播放?
  • 您想在页面加载时自动付款吗?
  • 请在您的答案中添加一些解释,以便其他人可以从中学习
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-02
  • 2017-11-03
  • 2011-09-06
  • 2017-05-20
  • 2011-11-28
  • 1970-01-01
相关资源
最近更新 更多