70

私の問題には、1つのリンクがあり<a href="http://www.youtube.com/embed/YT-ID" class="overlay_video"></a>ます。ファンシーボックスのオーバーレイウィンドウでリンクをクリックしてビデオを再生したい。これは問題ではありません。問題は、「autoplay」や「autohide」などのパラメーターです。

次のリンクは機能しません。

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

オーバーレイ ウィンドウが開きましたが、ビデオが自動的に再生されません。

編集: モバイル デバイスで HTML5 プレーヤーを使用したい。デスクトップブラウザーではパラメーターを使用できますが、モバイルデバイスでは機能しません。

4

6 に答える 6

72

結局のところ、自動再生はiOSデバイス(iPhone、iPad、iPod touch)およびAndroidでは実行できません。

https://stackoverflow.com/a/8142187/2054512およびhttps://stackoverflow.com/a/3056220/2054512を参照してください

于 2013-02-26T15:41:31.653 に答える
19

以下のコードを見てください。モバイルおよびタブレット デバイスで動作することがテストされ、確認されています。

<!-- 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>
于 2016-11-25T07:20:51.790 に答える
1

YouTube を自動再生し、完全なプレイリストを再生する方法があります。Android 用の Adblock ブラウザーを入手し、YouTube Web サイトにアクセスして、ページのデスクトップ バージョン用に構成し、Adblock ブラウザーを閉じてから再度開くと、自動再生が機能するデスクトップ バージョンが表示されます。

デスクトップ バージョンを使用すると、AdBlock が機能することも意味します。モバイル バージョンは、スタンドアロンの YouTube プレーヤーを呼び出します。そのため、自動再生が機能し、広告ブロックが機能するように、ページのデスクトップ バージョンが必要になります。

于 2016-01-09T07:15:27.353 に答える
0

Youtube チャンネルのライブ URL を使用して埋め込みと自動再生を行う方法。ライブ ストリームの変更に合わせて常に更新する必要がある動画 ID の代わりに。

2 組のコードを組み合わせて、チャンネルのライブ ストリームから埋め込まれた自動再生 Youtube ビデオを作成しました。

助けてくれた他の貢献者の両方に感謝します。うまくいけば、これは他の誰かを助けるでしょう。

サンプル ストリーム https://www.youtube.com/embed/live_stream?channel=UCwobzUc3z-0PrFpoRxNszXQ

Zubi による以下のコードは、16 年 11 月 25 日 7:20 に Youtube ビデオで動作します。

ダリエン・チャファートによるコードは、次の場所にあります。

https://stackoverflow.com/a/61126012/1804252

<html>
<head>



</head>
<body>
<center>



<script src="https://www.youtube.com/iframe_api"></script>

<!-- Insert Livestream Video -->
<iframe id="live-video" src="https://www.youtube.com/embed/live_stream?channel=UCwobzUc3z-0PrFpoRxNszXQ&enablejsapi=1" width="100%" height="100%" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen enablejsapi="1"></iframe>

<!-- Basic API code for Youtube videos -->
<script>
  var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('live-video', {
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    }
  });
}
function onPlayerReady() {
  var url = player.getVideoUrl(); /*Use Youtube API to pull Video URL*/
  var match = url.match(/[?&]v=([^&]+)/);
  var videoId = match[1]; /*Use regex to determine exact Video URL*/
  // Insert a new iFrame for the livestream chat after a specific div named chatframe*/
  var livevid = document.createElement("iframe");
  livevid.src = 'https://www.youtube.com/live_chat?v=' + videoId + ''
  livevid.width = '100%';
  livevid.height= '100%';
  document.getElementById("chatframe").appendChild(livevid);
}
    function onPlayerStateChange() {
    }

    
    function onPlayerReady(event) {
      event.target.playVideo();
    }

    // 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, 90000000);
        done = true;
      }
    }
    function stopVideo() {
      player.stopVideo();
    }
       
</script>



</center>
</body>
</html>
于 2021-12-15T16:04:14.297 に答える