Play and stop Youtube video in you page

var playVideo = function(player) {
var videoURL = player.prop(‘src’);
videoURL += “&autoplay=1”;
player.prop(‘src’,videoURL);
}

var stopVideo = function(player) {
var vidSrc = player.prop(‘src’);
vidSrc = vidSrc.replace(“&autoplay=1”, “”);
player.prop(‘src’, ”); // to force it to pause
player.prop(‘src’, vidSrc);
};

// Call the functions

$(‘.play-video’).click(function(e){
playVideo($(‘#video’));
});

$(‘.close-video’).click(function(e){
stopVideo($(‘#video’));
});

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s