【问题标题】:How Guest play a hidden youtube video in my website访客如何在我的网站上播放隐藏的 youtube 视频
【发布时间】:2021-11-13 02:04:44
【问题描述】:

我有一个真实访问的网站,我想为 youtube 生成一个机器人视图。

我如何让用户通过点击我网站上的任意位置进入网站并播放 youtube 视频(隐藏)?

例如,我不能使用下面的代码,因为如果我使用自动播放,youtube 不算作视图

<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>

我是初学者,试了下面的代码,还是不行。

<html> 
  <head> 
    <title>Youtube br</title>
  </head> 
  
  <style> #botYoutube { opacity: 0; position: absolute; right: 0; top: 0; } </style> 
  
  <body onclick="play()"> 
    
    <div id="botYoutube"></div> 
    
    <script async src="https://www.youtube.com/iframe_api"></script> 
    
    <script> 
       var player; 
       
       function play(){ 
           player.playVideo(); 
       } 

       function onYouTubeIframeAPIReady() { 
           player = new YT.Player('botYoutube', { 
               videoId: 'x5MhydijWmc', // YouTube Video ID 
               width: 10, // Player width (in px) 
               height: 10, // Player height (in px) 
               playerVars: { 
                   autoplay: 0, // Auto-play the video on load 
                   controls: 1, // Show pause/play buttons in player 
                   showinfo: 0, // Hide the video title 
                   modestbranding: 1, // Hide the Youtube Logo 
                   loop: 1, // Run the video in a loop 
                   fs: 0, // Hide the full screen button 
                   cc_load_policy: 0, // Hide closed captions 
                   iv_load_policy: 3, // Hide the Video Annotations 
                   autohide: 0 // Hide video controls when playing 
              }, 
              events: { 
                   onReady: function(e) { 
                       e.target.mute(); 
                   } 
              } 
          }); 
      } 
</script> 

</body> 

</html>

我用谷歌翻译来问这个问题!

谢谢

【问题讨论】:

  • 您的要求违反了 YouTube 的服务条款。

标签: javascript html css youtube


【解决方案1】:

这在 Youtube 上是不允许的,但是你可以创建一个白色背景的 div 和 420px×375px,和高 z-index 并将其放在播放器顶部
不要忘记自动播放:

autoplay: 0, // Auto-play the video on load 

【讨论】:

    【解决方案2】:

    您正在尝试做的事情违反了 Youtube 服务条款,并且无论如何都可能无法正常工作。 Youtube 有针对此类行为的保护措施。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 2013-02-14
      • 2012-03-08
      • 2016-07-26
      • 1970-01-01
      • 2019-05-01
      相关资源
      最近更新 更多