how to play a specific video of a play list in embedded youtube video

主宰稳场 提交于 2019-12-12 03:54:20

问题


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



来源:https://stackoverflow.com/questions/13365389/how-to-play-a-specific-video-of-a-play-list-in-embedded-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!