Using RoyalSlider with html5 <video> tags

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 14, 2018   (RSS)

By gkornbluth - December 13, 2018

Hi All,

Has anyone used html5 <video> tags with RoyalSlider to display a series of images and videos?

I've been trying to display my video using the <video> tags in a basic slider setup and everything works, except I can't seem to get the videos to play.

My RoyalSlider js does contain the video code.

Here's the simplest form of the working code (html) that I'm currently using, based on what I think the RoyalSlider documentation asks for.

(I have a more complex version for CMSB integration)

Thanks,

Jerry Kornbluth

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="http://www.rippedfromtheheadlines.art/royalslider/royalslider.css.php">
<link rel="stylesheet" href="http://www.rippedfromtheheadlines.art/royalslider/skins/default/rs-default.css">
<script src='http://www.rippedfromtheheadlines.art/royalslider/jquery-1.8.3.min.js'></script>
<script src="http://www.rippedfromtheheadlines.art/royalslider/jquery.royalslider.min.js"></script>
<style type='text/css'>
.royalSlider .rsNav, .royalSlider .rsGCaption {
position: relative;
float: left;
left: auto;
bottom: auto;
width: 100%;
text-align: center;
padding: 0;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
$('.royalSlider').royalSlider({
//autoScaleSlider:false,
controlNavigation: 'thumbnails',
autoScaleSlider: true,
arrowsNavHideOnTouch: true,
fitInViewport:true,
loop: true,
fullscreen: {
enabled: true,
nativeFS: false
},
globalCaption: true,
numImagesToPreload:2,
thumbs: {

}
});
$('.rsGCaption').after( $('.rsNav') );
}).data('royalSlider');
var slider = $('.royalSlider').data('royalSlider');
slider.ev.on('rsOnCreateVideoElement', function(e, url) {
slider.videoObj = $('<video src=" ' + url + '"></video>');
});

</script>

</head>

<body >
<div class="royalSlider rsDefault">
<div><a class="rsImg " href="http://www.rippedfromtheheadlines.art/cmsAdmin/uploads/the-economy.jpg"> </a>
<div class="rsTmb" > <img class="rsTmb" src="http://www.rippedfromtheheadlines.art/cmsAdmin/uploads/thumb/the-economy.jpg" /></div>
</div>
<div class="rsContent " > <a class="rsImg rsNoDrag" href="http://www.rippedfromtheheadlines.art/images/video.jpg" data-rsVideo="http://rippedfromtheheadlines.art/cmsAdmin/uploads/5-min-break.mp4">

</a>
<div class="rsTmb" > <img class="rsTmb" src="http://www.rippedfromtheheadlines.art/images/video.jpg" /></div>
</div>

</div>
</body>
</html>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - December 14, 2018

Hi Jerry,

It looks like the primary issue is that you're calling some of the JavaScript outside of the $(window).load() function, causing it to be executed out of order. As well, you'll probably want to add the autoplay property to the video so that it will play when the user clicks the slide's play button. It would look something like this:


<script type='text/javascript'>

$(window).load(function() {
  
  $('.royalSlider').royalSlider({
    //autoScaleSlider:false,
    controlNavigation: 'thumbnails',
    autoScaleSlider: true,
    arrowsNavHideOnTouch: true,
    fitInViewport: true,
    loop: true,
    fullscreen: {
      enabled: true,
      nativeFS: false
    },
    globalCaption: true,
    numImagesToPreload: 2,
    thumbs: {

    }
  });
  
  $('.rsGCaption').after($('.rsNav'));
      
  var slider = $('.royalSlider').data('royalSlider');
  slider.ev.on('rsOnCreateVideoElement', function(e, url) {
    slider.videoObj = $('<video autoplay="true" src=" ' + url + '"></video>');
  });

});

</script>

Let me know if that helps!

Thanks,

Daniel
Technical Lead
interactivetools.com