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

By gkornbluth - December 14, 2018 - edited: December 15, 2018

Hey Daniel,

I didn't expect that you'd be an expert with RoyalSlider as well. I'm impressed.

Your suggestion worked with one small tweak.

Instead of 'autoplay="true"', I used the 'controls' attribute, otherwise the video would remain playing even when advancing the slider to another slide, and would stack up playing copies of the video playing each time I returned to the video.

Here's the final code for the test html version:

<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 controls src=" ' + url + '"></video>');
});

});

</script>

And here's the body code for a CMSB implementation for a single record section with an upload field that allows multiple uploads of either images or .mp4 videos (the head code does not change):

div class="royalSlider rsDefault">
<?php foreach ($exhibition_submissionsRecords as $record): ?>
<?php foreach ($record['submissions'] as $index => $upload): ?>
<?php $recNum = $upload['num'] ?>
<?php if ($upload['extension'] == 'mp4'): ?>
<div class="rsContent" > <a class="rsImg" href="http://www.your_site.com/images/video_placeholder_image.jpg" data-rsVideo="http://your_site.com<?php echo $upload['urlPath'] ?>">
<?php else:?>
<div><a class="rsImg " href="<?php echo $upload['urlPath'] ?>">
<?PHP $upload['info1'] = preg_replace("/[\"]/", "''", $upload['info1'] ); // replace all double quotes with 2 single quotes?>
<?PHP $upload['info2'] = preg_replace("/[\"]/", "''", $upload['info2'] ); ?>
<?PHP $upload['info3'] = preg_replace("/[\"]/", "''", $upload['info3'] ); ?>
<?PHP $upload['info4'] = preg_replace("/[\"]/", "''", $upload['info4'] ); ?>
<?php endif ?>
<div align='center' style='font-size:1.4em; color:#FFF' class='sub_heading_font' >
<?php if($upload['info1']):?>
Title: <?php echo $upload['info1']?>
<?php else :?>
<span style="color:#C30">No Title</span>
<?php endif ?>
<br />
<?php if($upload['info2']):?>
Medium: <?php echo $upload['info2']?>
<?php else :?>
<span style="color:#C30">No Medium</span>
<?php endif ?>
<br />
<?php if($upload['info3']):?>
Dimensions: <?php echo $upload['info3']?>
<?php else :?>
<span style="color:#C30">No Dimensions</span>
<?php endif ?>
<br />
<?php if($upload['info4']):?>
Price: <?php echo $upload['info4']?>
<?php else :?>
<span style="color:#C30">No Price</span>
<?php endif ?>
<br />
</a>
<div class="rsTmb" > <img class="rsTmb" src="<?php if ($upload['extension'] == 'mp4'): ?>http://www.your_site.com/images/video_placeholder_image.jpg<?php else :?><?php echo $upload['thumbUrlPath'] ?><?php endif ?>" /></div>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
</div>

Thanks again,

Jerry

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