Youtube iframe API,订阅事件 [英] Youtube iframe API, subscribing to events
本文介绍了Youtube iframe API,订阅事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
YouTube iframe API:如何控制已经在HTML中的iframe播放器?
如何在这里订阅活动?我想听视频完成。
How do I subscribe to events here? I would like to listen for video finish.
推荐答案
看看我的功能,定义在这个答案: a href =https://stackoverflow.com/questions/7988476/listening-for-youtube-event-in-jquery/7988536#7988536>使用JavaScript或jQuery收听Youtube事件 。
Have a look at my function as defined at this answer: Listening for Youtube Event in JavaScript or jQuery.
在你的情况下,实现核心功能如下所示( Fiddle: http://jsfiddle.net/w2w5x/ )
In your case, implement the core functions as shown below (Fiddle: http://jsfiddle.net/w2w5x/)
// Core functions defined at https://stackoverflow.com/q/7988536#7988536
var player;
YT_ready(function(){
var frameID = getFrameID("YOUR-frame-or-container-ID-here");
if (frameID) { //If the frame exists
player = new YT.Player(frameID, {
events: {
"onStateChange": function(event){
if(event.data == "0") {
//The video has finished
alert("The video has finished!");
//Do something, example: play again
player.playVideo();
}
}
}
});
}
});
这篇关于Youtube iframe API,订阅事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文