how to play a specific video of a play list in emb

2019-09-12 06:12发布

问题:

I have followed this tutorial http://www.lavacoms.com/2012/01/embedded-youtube-playlist-autoplay/

it is an excellent tutorial. my question is if I have a playlist embedded on my page but I would like the first video to be let say the second or the third video or even the sisth video of the play list what do I have to do?

Thank you

回答1:

<iframe src="http://www.youtube.com/embed/VIDEO_ID?list=PLAYLISTURL&amp;autoplay=1&amp;modestbranding=1&amp;fs=2" frameborder="0" width="640" height="385"></iframe>

where it said VIDEO_ID put the video Id that you want to play first from your play list. where it said PLAYLISTURL put the ID of the url.

found on http://911-need-code-help.blogspot.com/2012/07/youtube-iframe-embeds-video-playlist-and-html5.html

hope it helps someone else



回答2:

Considering an array ($filas) of VIDEO_ID on php, you can add like follows:

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      videoId: '<?php echo $filas[0]["trailer"]; ?>',
      playerVars: { 'autoplay': 1, 'controls': 1, 'enablejsapi': 1, 'frameborder': 0,
      'playlist': '<?php for ( $i=1; $i < count($filas); $i++) { if($i == count($filas) -1) echo $filas[$i]["trailer"]; else echo $filas[$i]["trailer"].", "; } ?>' },
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange,
        'onError': onError
      }
    });
  }

Please be sure to catch error just in case a video cannot be played