The easiest way to show ad breaks, breakpoints, and bookmarks on your videojs player.
Add breakpoints on the video progress bar, hover-over tooltips and break overlays.
<video id="demo" controls class="video-js vjs-default-skin">
<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>
<script>
var player = videojs('demo');
player.markers({
markers: [
{time: 9.5, text: "this"},
{time: 16, text: "is"},
{time: 23.6,text: "so"},
{time: 28, text: "cool"}
]
});
</script>
Fully customize the styles and text for your markers, tooltip and overlays.
<video id="demo" controls class="video-js vjs-default-skin">
<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>
<style>
.special-blue{
background-color: #4949d8 !important;
}
</style>
<script>
var player = videojs('demo');
player.markers({
markerStyle: {
'width':'9px',
'border-radius': '40%',
'background-color': 'orange'
},
markerTip:{
display: true,
text: function(marker) {
return "I am a marker tip: "+ marker.text;
}
},
breakOverlay:{
display: true,
displayTime: 4,
style:{
'width':'100%',
'height': '30%',
'background-color': 'rgba(10,10,10,0.6)',
'color': 'white',
'font-size': '16px'
},
text: function(marker) {
return "This is a break overlay: " + marker.overlayText;
},
},
markers: [
{time: 9.5, text: "this", overlayText: "1", class: "special-blue"},
{time: 16, text: "is", overlayText: "2"},
{time: 23.6,text: "so", overlayText: "3"},
{time: 28, text: "cool", overlayText: "4"}
]
});
</script>
Dynamically add or remove markers on the fly.
<video id="demo" controls class="video-js vjs-default-skin">
<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>
<script>
var player = videojs('demo');
player.markers({
breakOverlay:{
display: true
},
onMarkerClick: function(marker){
$('.dynamic-demo-events').append('Marker click: '+marker.time+' ');
},
onMarkerReached: function(marker){
$('.dynamic-demo-events').append('Marker reached: '+marker.time+' ');
},
markers: [
{time: 9.5, text: "this", overlayText: "1"},
{time: 16, text: "is", overlayText: "2"},
{time: 23.6,text: "so", overlayText: "3"},
{time: 28, text: "cool", overlayText: "4"}
]
});
// setup control handlers
$(".dynamic-demo-prev").click(function(){
player.markers.prev();
});
$(".dynamic-demo-next").click(function(){
player.markers.next();
});
$(".dynamic-demo-add-random").click(function(){
var randomTime = Math.floor((Math.random() * parseInt(player.duration())) + 1);
// come up with a random time
player.markers.add([{
time: randomTime,
text: "I'm new",
overlayText: "I'm new"
}]);
});
$(".dynamic-demo-shift"). click(function(){
var markers = player.markers.getMarkers();
for(var i = 0; i < markers.length; i++) {
markers[i].time += 1;
}
player.markers.updateTime();
});
$(".dynamic-demo-remove-first").click(function(){
player.markers.remove([0]);
});
$(".dynamic-demo-remove-all").click(function(){
player.markers.removeAll();
});
$(".dynamic-demo-destroy").click(function(){
player.markers.destroy();
});
</script>
Include jquery.min.js
, video-js.css
and video.js
:
<link href="http://vjs.zencdn.net/4.3/video-js.css" rel="stylesheet">
<link href="src/to/videojs.markers.css" rel="stylesheet">
...
<script src="http://code.jquery.com/jquery-2.0.3.min.js"> </script>
<script src="http://vjs.zencdn.net/4.3/video.js"></script>
<script src='src/to/videojs.markers.js'></script>
// initialize video.js
var player = videojs('video-id');
//load the marker plugin
player.markers({
markers: [
{
time: 9.5,
text: "put"
},
{
time: 16,
text: "any"
},
{
time: 23.6,
text: "text"
},
{
time: 28,
text: "here"
}
]
});
// setup plugin
player.markers({
markerStyle: {
'width':'7px',
'border-radius': '30%',
'background-color': 'red'
},
markerTip:{
display: true,
text: function(marker) {
return "Break: "+ marker.text;
},
time: function(marker) {
return marker.time;
}
},
breakOverlay:{
display: false,
displayTime: 3,
style:{
'width':'100%',
'height': '20%',
'background-color': 'rgba(0,0,0,0.7)',
'color': 'white',
'font-size': '17px'
},
text: function(marker) {
return "Break overlay: " + marker.overlayText;
}
},
onMarkerClick: function(marker) {},
onMarkerReached: function(marker) {},
markers: [{
time: 9.5,
text: "marker",
overlayText: 'overlay',
class: 'custom-marker'
}]
});
// plugin api
player.markers.next();
player.markers.prev();
player.markers.remove([1,2]);
player.markers.removeAll();
player.markers.add([{ time: 40, text: "I'm added"}]);
player.markers.reset([{ time: 23, text: "I'm reset"}]);
player.markers.destroy();
Name | Type | Description | |
---|---|---|---|
markerStyle |
Object |
The general css styling that would be applied to all the markers created by the plugin. The default is only concerned with Set up square, orange markers:
|
|
markerTip |
Object | Options for hover-over marker tips. | |
display |
Boolean | Whether markerTips are displayed or not. Default to |
|
text |
Function |
Callback function for dynamically constructing your marker tip text. Simply return a string. The argument Show time of the marker (
|
|
time |
Function |
Callback function for dynamically getting the time for the marker. The plugin makes no assumption of where the time attribute is located in the marker object. This allows you to use existing formats to represent time (in seconds). The default function uses |
|
breakOverlay |
Object | Options for the break overlays at each marker. | |
display |
Boolean | Whether overlays are displayed or not. Default to |
|
displayTime |
Integer | The number of seconds a overlay is shown from the beginning of its marker.. Default to |
|
style |
Object | Setup css styles for the overlays (play around with color, font-size, and height). Similar to |
|
text |
Function |
Same idea as markerTip's
|
|
onMarkerReached |
Function | This callback function is triggered whenever playback reaches the time interval from a marker. The interval is specified in the
|
|
onMarkerClick |
Function | This callback function is triggered when clicking on the markers. The default behavior for clicking on the marker is seeking to that point in the video. However, if
|
|
markers |
Array |
An array of markers to display by the plugin. For each marker, you can specify the following:
The
|
Name | Description | |
---|---|---|
getMarkers |
Returns the array of current markers in the plugin, sorted by ascending time. |
|
next |
Go to the next marker from the current time in the video. If there's isn't a next marker, then does nothing. |
|
prev |
Go to the pervious marker from the current time in the video. If there's isn't one, then does nothing. |
|
updateTime |
Starting in v0.5.0, we allow modifying the marker's time dynamically (from the original marker object passed in). Once marker times have been changed, Add a second to all the markers
|
|
remove |
Remove the markers in the given array of indices. Note the index is 0-based (e.g. first marker has index 0). Remove the 2nd and 3rd marker:
|
|
removeAll |
Remove all the markers in the player. |
|
add |
Dynamically add new markers.
|
|
reset |
Reset all the markers in the video. This is equivalent to removeAll then add new markers.
|
|
destroy |
Destroy the plugin. After calling this function, player.markers should be undefined. |