Ok try the below modified version of the script. When a youtube video is played in one of the slides, at the end, the script automatically goes to the next slide and plays that video, doing so until a video is stopped.
First is the modified featuredcontentglider.js file, which only differs from the original slightly (by caching the config object). Then comes the modified onYouTubeIframeAPIReady() function, with changes in red against the standard markup and code you paste to your page:
Code:
<!doctype html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="featuredcontentglider.css" />
<script type="text/javascript" src="featuredcontentglider.js">
/***********************************************
* Featured Content Glider script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/
</script>
<script>
featuredcontentglider.init({
gliderid: "canadaprovinces", //ID of main glider container
contentclass: "glidecontent", //Shared CSS class name of each glider content
togglerid: "p-select", //ID of toggler container
remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
selected: 0, //Default selected content index (0=1st)
persiststate: false, //Remember last content shown within browser session (true/false)?
speed: 500, //Glide animation duration (in milliseconds)
direction: "downup", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
autorotate: false, //Auto rotate contents (true/false)?
autorotateconfig: [3000, 2], //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
onChange: function(previndex, curindex, $allcontents){ // fires when Glider changes slides
if (previndex != curindex)
playpausevideo($allcontents.eq(previndex).data('youtubeplayer'), 'pause') //pause previous slide's video
}
})
</script>
<script type="text/javascript">
function onYouTubeIframeAPIReady(){ // this function is called automatically when Youtube API is loaded (see: https://developers.google.com/youtube/iframe_api_reference)
jQuery(function($){ // when DOM has loaded
var $contentdivs = $('#canadaprovinces').find('div.glidecontent')
$contentdivs.each(function(i){ // loop through the content divs
var $contentdiv = $(this)
var $youtubeframe = $contentdiv.find('iframe[src*="youtube.com"]:eq(0)') // find Youtube iframe within DIV, if it exists
if ($youtubeframe.length == 1){
var player = new YT.Player($youtubeframe.get(0), { // instantiate a new Youtube API player on each Youtube iframe (its DOM object)
events: {
'onReady': function(e){e.target._donecheck=true} // indicate when video has done loading
}
})
player.addEventListener("onStateChange", function(e){
if (e.data == 0){ // if finished playing current video
var targetconfig = featuredcontentglider.configs["canadaprovinces"]
var nextslide = parseInt(targetconfig.$next.get(0).getAttribute('loadpage'))
featuredcontentglider.glide(targetconfig, nextslide, "next") // go to next slide
playpausevideo($contentdivs.eq(nextslide).data('youtubeplayer'), 'play')
}
})
$contentdiv.data("youtubeplayer", player) // store Youtube API player inside contentdiv object
}
})
})
}
function playpausevideo(player, action){
if (player && player._donecheck === true){
if (action == "play")
player.playVideo()
else if (action == "pause")
player.pauseVideo()
}
}
</script>
<!--Youtube API reference. Should follow onYouTubeIframeAPIReady() above, not proceed: -->
<script src="http://www.youtube.com/iframe_api"></script>
</head>
<body>
<div id="canadaprovinces" class="glidecontentwrapper">
<div class="glidecontent">
<iframe width="330" height="210" src="http://www.youtube.com/embed/KWFfDyupGpQ?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
<div class="glidecontent">
<iframe width="330" height="210" src="http://www.youtube.com/embed/to7uIG8KYhg?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
<div class="glidecontent">
<iframe width="330" height="210" src="http://www.youtube.com/embed/RP4abiHdQpc?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
<div class="glidecontent">
<iframe width="330" height="210" src="http://www.youtube.com/embed/FNeaQtFuBns?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div id="p-select" class="glidecontenttoggler">
<a href="#" class="prev">Prev</a>
<a href="#" class="toc">Page 1</a> <a href="#" class="toc">Page 2</a> <a href="#" class="toc">Page 3</a> <a href="#" class="toc">Page 4</a>
<a href="#" class="next">Next</a>
</div>
</body>
</html>
Bookmarks