Skip to content

Instantly share code, notes, and snippets.

@mmcc
Last active December 17, 2015 12:29
Show Gist options
  • Save mmcc/5610541 to your computer and use it in GitHub Desktop.
Save mmcc/5610541 to your computer and use it in GitHub Desktop.
Video.js example cue plugin for Spree Conf.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link href="http://vjs.zencdn.net/4.0/video-js.css" rel="stylesheet">
<style>
.product {
display:none;
}
.product img {
float: left;
margin-right: 5px;
}
</style>
</head>
<body>
<video id="awesome-product-video" class="video-js vjs-default-skin" controls
preload="auto" width="640" height="264" poster="http://f.cl.ly/items/3c1x0u0z03361k473x0f/poster.png" data-setup="{}">
<source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
<source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">
</video>
<div id="bird" class="product">
<img src="http://f.cl.ly/items/1H061H2x2f0E212S3L47/bird.png"/>
<h3>Bird!</h3>
<p>This is an awesome bird, and you should look into it more.</p>
</div>
<div id="dolphins" class="product">
<img src="http://f.cl.ly/items/441E3a42252G2g3w0Z0S/dolphin.png"/>
<h3>Dolphins</h3>
<p>This is a dolphin, I hear they're really smart.</p>
</div>
<div id="whale" class="product">
<img src="http://f.cl.ly/items/1B0x1S1R1X2C383y0n47/whale.png"/>
<h3>Whale</h3>
<p>Whales are really big, and would probably be expensive.</p>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://vjs.zencdn.net/4.0/video.js"></script>
<script src="plugin.js"></script>
<script type="text/javascript">
videojs.plugin('cuePoint', cuePoint);
var vjs = videojs('awesome-product-video');
vjs.cuePoint({
0.1: {
length: 5,
element: '#bird'
},
15: {
length: 4,
element: '#dolphins'
},
37: {
length: 7,
element: '#whale'
}
});
</script>
</body>
</html>
function cuePoint(options) {
var vjs = this;
var addCue = function(cue, value) {
var start = parseInt(cue);
var end = start + value.length;
vjs.on('timeupdate', function(e) {
if (vjs.currentTime() >= cue && vjs.currentTime() <= end) {
$(value.element).show();
} else {
$(value.element).hide();
}
})
}
var key, value;
for (key in options) {
value = options[key];
addCue(key, value);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment