admin管理员组文章数量:1289901
I'm embedding YouTube videos onto my webpage with something like this
<object width="425" height="344">
<param name="movie" value=""></param>
<param name="allowFullScreen" value="false"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>
If I have say 3 YouTube videos on the same webpage, I was wondering if it was possible (maybe with YouTube's API?) to play each video consecutively? That is, the first video starts to autoplay. When that video finishes, the second video on the webpage will play and then the third? Thanks for your time.
Reference: .html
I'm embedding YouTube videos onto my webpage with something like this
<object width="425" height="344">
<param name="movie" value="http://www.youtube./v/RU-bMtPz1cY"></param>
<param name="allowFullScreen" value="false"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube./v/RU-bMtPz1cY" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>
If I have say 3 YouTube videos on the same webpage, I was wondering if it was possible (maybe with YouTube's API?) to play each video consecutively? That is, the first video starts to autoplay. When that video finishes, the second video on the webpage will play and then the third? Thanks for your time.
Reference: http://code.google./apis/youtube/js_api_reference.html
Share Improve this question asked Feb 25, 2010 at 18:07 axsuulaxsuul 7,4909 gold badges59 silver badges72 bronze badges3 Answers
Reset to default 5See http://code.google./apis/youtube/js_api_reference.html#Events
You want to listen to the onStateChange
event. note that when the value passed is 0
, then the video has ended. Listen for that event/value to start the next video.
Just a basic outline of what you probably want to do:
- add end listener for video
- play video
- when end event fired (and caught), go to next video and repeat from step 1.
You could use a jQuery plugin -- the jQuery YouTube TubePlayer Plugin
provided you have the right markup, (in this example - an an 'active' class on the video thats currently playing) you could basically set something up like..
jQuery("#player-container").tubeplayer({
onPlayerEnded:function(){
var $vid = jQuery(".active").next();
if($vid.length){
jQuery('#player-container').tubeplayer('play',vid.attr("vid");
$vid.siblings().andSelf().removeClass("active");
$vid.addClass("active");
}
}
});
You're going to want to create a playlist containing the videos you want to play and then embed that into your site. Direct instructions can be found here.
本文标签: javascriptPlaying YouTube embedded videos consecutively on one pageStack Overflow
版权声明:本文标题:javascript - Playing YouTube embedded videos consecutively on one page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741420113a2377752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论