admin管理员组文章数量:1288021
I'm supposed to create a sort of youtube video rotator using jquery. I've looked around and there seemed to be no plugin that's fit for the requirement. Not even a solution.
Maybe I'll just try to make this. So now, how can I determine that a youtube video is done playing and automatically play the next, using Jquery, or simply just javascript?
And if you happen to know a plugin which may help, please point out.
Thanks
I'm supposed to create a sort of youtube video rotator using jquery. I've looked around and there seemed to be no plugin that's fit for the requirement. Not even a solution.
Maybe I'll just try to make this. So now, how can I determine that a youtube video is done playing and automatically play the next, using Jquery, or simply just javascript?
And if you happen to know a plugin which may help, please point out.
Thanks
Share Improve this question asked Jan 19, 2011 at 8:08 tidustidus 911 silver badge2 bronze badges 1- 1 Doesn't YouTube have a playlist functionality where you can queue up videos to auto-rotate? -- EDIT Case in point: youtube./custom_player – Brad Christie Commented Jan 19, 2011 at 8:10
1 Answer
Reset to default 12First you have to make sure the youtube player you're embedding supports javascript by passing enablejsapi=1
as a get param. Here's how I insert a (chromeless) player using SWFObject:
var player_id = "your_player_id";
var params = { allowScriptAccess: "always" };
var url = "http://www.youtube./apiplayer?enablejsapi=1&version=3&playerapiid=" + player_id;
swfobject.embedSWF(url, player_id, '320', '240', "9.0.0", null, null, params, {'id': player_id});
Then you need to add a global function that is called when the player is ready, and in that add a listener for when a video is plete:
var player = null;
function onYouTubePlayerReady(player_id) {
player = document.getElementById(player_id);
player.addEventListener('onStateChange', 'playerStateChanged');
player.loadVideoById(youtube_video_id);
};
function playerStateChanged(state) {
// State code 0 means playback ended
if (state == 0) {
player.loadVideoById(next_video_id);
}
};
I wrote this code for my youtube playlist bookmarklet. Here's a link if you want a working example: http://zaius.github./youtube_playlist/
And if you want to do anything more in depth, here's the youtube javascript reference where I worked out how to do all this: http://code.google./apis/youtube/js_api_reference.html
本文标签: jqueryCatch the event when a youtube flash video is done playing using javascriptStack Overflow
版权声明:本文标题:jquery - Catch the event when a youtube flash video is done playing using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741336384a2373064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论