首页 文章

Youtube自动播放不适用于具有嵌入式HTML5播放器的移动设备

提问于
浏览
47

对我的问题,我有一个链接 <a href="http://www.youtube.com/embed/YT-ID" class="overlay_video"></a> . 我想通过单击fancybox覆盖窗口中的链接来播放视频 . 这不是问题 . 问题是参数,例如"autoplay"或"autohide" .

以下链接不起作用:

<a href="http://www.youtube.com/embed/YT-ID?autoplay=1" class="overlay_video"></a>

Overlay-Window已打开,但视频未自动播放 .

EDIT: I want to use the HTML5 Player on mobile devices. On a desktop-browser it works with the parameters, but not on mobile devices.

3 回答

  • 50

    事实证明,无法在iOS设备(iPhone,iPad,iPod touch)和Android上进行自动播放 .

    https://stackoverflow.com/a/8142187/2054512https://stackoverflow.com/a/3056220/2054512

  • 1

    看看下面的代码 . 测试并发现在移动和平板电脑设备上工作 .

    <!-- 1. The <iframe> (video player) will replace this <div> tag. -->
    <div id="player"></div>
    
    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
    
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'M7lc1UVf-VE',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }
    
      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }
    
      // 5. The API calls this function when the player's state changes.
      //    The function indicates that when playing a video (state=1),
      //    the player should play for six seconds and then stop.
      var done = false;
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
      }
      function stopVideo() {
        player.stopVideo();
      }
    </script>
    
  • 8

    有一种方法可以让youtube自动播放,完整的播放列表可以播放 . 获取适用于Android的Adblock浏览器,然后转到youtube网站,并将其配置为桌面版本的网页,关闭Adblock浏览器,然后重新打开,您将拥有桌面版本,其中autoplay将起作用 .

    使用桌面版也意味着AdBlock可以正常运行 . 移动版本调用独立的YouTube播放器,这就是您需要页面的桌面版本的原因,以便自动播放可以正常工作,因此广告拦截功能将起作用 .

相关问题