2.0.2 • Published 4 years ago
@silaas/videojs-preroll v2.0.2
videojs-preroll
A plugin based on videojs-contrib-ads to play preroll ads in VideoJS.
Installation
npm install --save @silaas/videojs-prerollPlugin Options
Default options
{
src: '',
href: '',
target: '_blank',
allowSkip: true,
skipTime: 5,
repeatAd: false,
adSign: false,
showRemaining: false,
adsOptions: {},
lang: {
'skip': 'Skip Ad ≫',
'skip in': 'Skip in ',
'advertisement': 'Advertisement',
'video start in': 'Video will start in: '
}
}Options
- src
stringSource video file to play. Can be any valid videojs src parameter. - href
stringUrl to redirect to if user clicks on the ad. Can be left empty for no redirection. - target
stringTarget to open the url in (eg _blank or _top). - allowSkip
booleanAllow the user to skip the ad when it has played for a number of seconds. - skipTime
intNumber of seconds after which the video can be skipped. - repeatAd
booleanWhether the ad should be repeated if a new src is loaded to the player. - adSign
booleanAdds an "Advertisement" sign to the video. - showRemaining
booleanShow the remaining time of the ad (only ifallowSkipis set to false.) - adsOptions
objectSettings object passed to the videjs-contrib-ads plugin. - lang
objectLanguage strings for skip button, "Advertisement" sign and remaining ad time element.
Usage
To include videojs-preroll on your website or web application, use any of the following methods.
<script> Tag
This is the simplest case. Get the script in whatever way you prefer and include the plugin after you include video.js, so that the videojs global is available.
<script src="//path/to/video.min.js"></script>
<script src="//path/to/videojs-preroll.min.js"></script>
<link src="//path/to/videojs-preroll.min.css"></link>
<script>
var player = videojs('my-video');
player.preroll();
</script>Browserify/CommonJS
When using with Browserify, install videojs-preroll via npm and require the plugin as you would any other module.
var videojs = require('video.js');
// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
import('@silaas/videojs-preroll/dist/videojs-preroll.css');
require('@silaas/videojs-preroll');
var player = videojs('my-video');
player.preroll();RequireJS/AMD
When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require the plugin as you normally would:
require(['video.js', 'videojs-preroll'], function(videojs) {
var player = videojs('my-video');
player.preroll();
});License
MIT. Copyright (c) Silaas <silaas.tech@gmail.com>