开发者

Youtube embeded action when video ends

开发者 https://www.devze.com 2023-03-18 18:48 出处:网络
I wonder if it is possible to make an action with youtube api when embeded video finishes. For example, in my web开发者_运维知识库 i start video on hover of one element, but i want video tu be replace

I wonder if it is possible to make an action with youtube api when embeded video finishes. For example, in my web开发者_运维知识库 i start video on hover of one element, but i want video tu be replaced by static image when it finishes. How can i do that?


I had wordpress and used in suchh steps: installed http://www.tikku.com/jquery-youtube-tubeplayer-plugin

then add this code into page
but change
1) yoursite.com to yours
2) alert("Hello"); to your another desired function;
3) DkoeNLuMbcI to desired video 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>


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

It makes everything easy. Once you have it set up, which shouldn't take long (there is an easy how-to), simply add this line to you player initiation:

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

This will do whatever you want after the player ends. There are also callbacks for when the player is paused, stopped, played, muted, unmuted, queued, and more

Let me know if this works, or if you have trouble using the jquery plugin. It really is very helpful and easy!

0

精彩评论

暂无评论...
验证码 换一张
取 消