YouTube の埋め込み動画をリピート再生させる

YouTube の動画を埋め込んだ際に、リピート再生させる方法をメモ書きしておきます。

埋め込み動画を Web サイトに埋め込む際には、 動画を再生しているページで共有 → 埋め込みコード を選択すると「埋め込みコード」を表示させることができます。

YouTube

<iframe width="560" height="315" src="//www.youtube.com/embed/〇〇” frameborder="0" allowfullscreen></iframe>

src で指定している URL に GET パラメーターを渡すことでプレイヤーの見た目や挙動を変更することができるようになっています。

YouTube Embedded Players and Player Parameters

今回は動画をリピート再生させたいので、 loop というずばりなパラメーターに 1 という値を渡してみます。

<iframe width="560" height="315" src="//www.youtube.com/embed/〇〇?loop=1” frameborder="0" allowfullscreen></iframe>

しかしこれだけではできませんでした

解決法

先ほどのリンク先で loop パラメーターの説明を見てみます。

To loop a single video, set the loop parameter to 1 and set the playlist parameter value to the same video ID already specified in the Player API URL

とのことなので playlist というパラメーターで同じ動画の ID を指定して再生してあげればループが有効になるようです。

<iframe width="560" height="315" src="//www.youtube.com/embed/〇〇?loop=1&playlist=〇〇” frameborder="0" allowfullscreen></iframe>

こんな感じです。

実際に動くサンプルも下記にのせておきました。

サンプル

むねいっぱ〜い!