Youtube在视频结束时嵌入动作

时间:2011-07-08 13:10:47

标签: youtube youtube-api

我想知道在嵌入视频完成时是否可以使用youtube api进行操作。例如,在我的网络中,我在一个元素悬停时启动视频,但我希望视频在完成时被静态图像替换。我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

我有wordpress并在以下步骤中使用: 已安装http://www.tikku.com/jquery-youtube-tubeplayer-plugin

然后将此代码添加到页面
但改变了 1) yoursite.com 给你的 2)警告(“你好”); 到你想要的另一个功能;
3) DkoeNLuMbcI 到所需的视频ID;

<div id="youtube-player-container" style="float:right"> </div>
<script type="text/javascript" src="http://yoursite.com/folder/jQuery.tubeplayer.min.js"></script>
<script type="text/javascript">
jQuery("#youtube-player-container").tubeplayer({
    width: 422, // the width of the player
    height: 285, // the height of the player
    allowFullScreen: "true", // true by default, allow user to go full screen
    initialVideo: "DkoeNLuMbcI?autoplay=1", // the video that is loaded into the player
    preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
    onPlay: function(id){}, // after the play method is called
    onPause: function(){}, // after the pause method is called
    onStop: function(){}, // after the player is stopped
    onSeek: function(time){}, // after the video has been seeked to a defined point
    onMute: function(){}, // after the player is muted
    onPlayerEnded: function(){ alert("Hello"); },
    onUnMute: function(){} // after the player is unmuted
});
</script>

答案 1 :(得分:1)

使用http://www.tikku.com/jquery-youtube-tubeplayer-plugin

它让一切变得简单。一旦你完成了设置,这不应该花很长时间(有一个简单的操作方法),只需将这一行添加到玩家启动:

    onPlayerEnded: function(){ // Do something here },

这将在玩家结束后做任何你想做的事。播放器暂停,停止,播放,静音,取消静音,排队等等时还有回调

让我知道这是否有效,或者如果您在使用jquery插件时遇到问题。这真的非常有帮助而且很容易!