1.9.0 • Published 4 years ago

gg-ez-vp v1.9.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

GG EZ Video Player

Simple video player with minimal setup, intuitive API and straightforward features.

Player

Features:

  • Easy setup
  • Customizable controls (or use our slick defaults!)
  • Lightweight
  • Programmatic access to video playback APIs
  • Browser (UMD), CommonJS and ES module versions
  • VAST / VPAID Support for a single Linear Creative. Parsing is provided by dailymotion/vast-client-js. Note that at the time, only one Ad is loaded, and only Linear Creatives are played and tracked.

See the demo page

Table of contents

Installation

Browser

<!-- latest stable version -->
<script src="https://c.gumgum.com/vp/latest/gg-ez-vp.js">

<!-- beta version | synced with develop branch  -->
<script src="https://c.gumgum.com/vp/beta/gg-ez-vp.js">

<!-- or specific release, replace "1.x.x" with the release you want to use -->
<script src="https://c.gumgum.com/vp/1.x.x/gg-ez-vp.js">

Note: One of GumGum's solutions, is contextual advertising, as such, our CDN is blocked by ad blockers; if the scripts are not loading, disable the ad blocker or use an external CDN (TBD #21).

CommonJS

TODO: Installation

const GgEzVp = require('gg-ez-vp');

ES Modules

TODO: Installation

import GgEzVp from 'gg-ez-vp';

Usage

GgEzVp works by attaching itself to a unique container, ideally an empty <div> with a unique id:

<body>
    <div>
        <div class="randomContent">
            Some content
        </div>
        <div id="myVideo" class="myVideoStyles"></div>
    </div>
</body>

Then, to create a player instance:

// js
const minimalConfiguration = {
    container: 'myVideo',
    src: 'myvideo.mp4'
};

const ggEzVpInstance = new GgEzVp(minimalConfiguration);

This minimal configuration will create a unique video player instance using the defaults set by GgEzVp.

note: src and container are the only required options in the configuration object.

Customization

Options:

keydefaultValuerequireddescription
containernulltrueeither a node's id or the DOM node itself where the player will be loaded to
srcnulltruestring or array of strings used to retrieve video and/or VAST
widthnullfalseby default the player will take available space, unless width is specified
heightnullfalseby default the player will take available space, unless height is specified
controlsobjectfalsespecific controls configurations, see Controls section below
autoplayfalsefalsewhether to play the video automatically or not
volume1falseinitial volume for playback must be between 0.0 and 1
mutedtruefalsevideo will be muted by default
playsinlinetruefalseA Boolean attribute indicating that the video is to be played within the element's playback area.
posternullfalsesource for an image to be used as video poster
preload'auto'falsestandard HTML values for preload (nonemetadataauto)
loopfalsefalsewhether to loop video or not
isVASTfalsefalseenables support for a single VAST / VPAID TAG to be parsed and used as source, will force displaying the ad controls
adControlsfalsefalseforces displaying the ad controls instead of the regular contols

Controls

Besides the programmatic interaction with the player, there are also a number of controls displayed by default, they can be toggled by passing a controls property in the initial configuration. See the Styles section for information on how to customize the visuals.

Player

controlNamedefaultValuedescription
timestamptruedisplay the current time of the video in the format m:ss
volumetruedisplay the volume controls (mute toggle and range input)
volumeRangetruethe volume range input can be hidden if only the volume button is needed
progresstruedisplay the playback progress bar, clicking on the bar will set the video currentTime to the selected percentage (except on Ads)
playtrueshow the play/pause button
expandtrueshow the expand to fullscreen button
timestampAdfalseused only for Ads, will display the remaining time in the format Ad ss
skipfalseused only for Ads, will display a skip button

Additionally, passing the adControls: true option, will display a different set of controls for Ads:

Ad Controls

controlNamedefaultValuedescription
timestampAdtruedisplay the remainingTime time of the ad in the format Ad ss.
skiptruedisplay a skip button, pressing it will emit the 'skip' event
progresstruethe progress bar will display, but it won't show the scrub, nor it be possible to set the time with it
playtrueshow the play/pause button
expandtrueshow the expand to fullscreen button

Note: the timestamp control will be disabled when adControls is true and instead timestampAd will be displayed.

Control configuration examples

// Controls off
const controlsOffConfig = {
    container: 'myVideo',
    src: 'myvideo.mp4',
    controls: false
};

// timestamp and volume off
const customControls = {
    container: 'myVideo',
    src: 'myvideo.mp4',
    controls: {
        timestamp: false,
        volume: false
    }
};

// ad timestamp, skip and expand off
const customControls = {
    container: 'myVideo',
    src: 'myvideo.mp4',
    adControls: true, // will enable ad controls
    controls: {
        timestampAd: false,
        expand: false,
        skip: false
    }
};

Styles

To use the default styles, just include the styles.css file before loading the player's javascript:

<!-- latest version of the styles -->
<link src="https://c.gumgum.com/vp/latest/gg-ez-vp.css">

The default styles that can be overridden by any custom styles you may need:

.gg-ez-vp--play {
    background: url('/images/my-custom-play-btn.png');
    width: 40px;
    height: 40px;
}

.gg-ez-vp--progress-filled {
    background: red;
}

It is encouraged to override the styles rather than completely writing your own.

Use these selectors to override the styles:

selectorcomponent
.gg-ez-vpplayer container
.gg-ez-vp--viewervideo element
.gg-ez-vp--controlscontrol bar
.gg-ez-vp--timestampcurrent video time
.gg-ez-vp--timestamp-breakbar dividing currentime / duration
.gg-ez-vp--timestamp-adad remaining time
.gg-ez-vp--volumevolume controls container
.gg-ez-vp--volume-controlvolume slider container
.gg-ez-vp--volume-control-slidervolume slider
.gg-ez-vp--input-rangevolume slider input styles
.gg-ez-vp--progressprogress container
.gg-ez-vp--progress-barprogress track
.gg-ez-vp--progress-filledprogress bar fill
.gg-ez-vp--progress-filled:afterprogress bar scrub
.gg-ez-vp--button-iconplay and volume buttons
.gg-ez-vp--button-icon.mutemuted state of the volume control
.gg-ez-vp--button-icon.lowlow volume state of the volume control (under 33%)
.gg-ez-vp--button-icon.mediummedium volume state of the volume control (between 34% and 66%)
.gg-ez-vp--button-icon.highhigh volume state of the volume control (above 66%)
.gg-ez-vp--button-icon.playshown while video is not playing on the play control
.gg-ez-vp--button-icon.pauseshown while video is playing on the play control
.gg-ez-vp--button-icon.replayshown after the video ends
.gg-ez-vp--button-icon.expandexpand button icon
.gg-ez-vp--blockerinvisible div that can be used to prevent clicks on VPAID/VAST thumbnails
.gg-ez-vp--slotinvisible div used as VPAID slot

There are also a few modifier selectors applied to the container .gg-ez-vp:

selectordescription
.gg-ez-vp--no-scrubapplied on adControls: true. Prevents displaying the scrub and adjusts ad styles.
.gg-ez-vp--skipapplied when the skip button will be displayed
.gg-ez-vp--volume-onlyadjusts the styles when only the volume toggle button is displayed
.gg-ez-vp--touchscreenadded when the device uses a touchscreen, this will show all enabled controls instead of activating them on hover

See src/styles.css for all styles.

Public methods

method nameparametersdescription
destroynoneremoves all instance and video tag listeners, removes the player from the DOM leaving behind the original container
fullscreenTogglenonetoggles the fullscreen mode
getCurrentTimenonereturns the currentTime from the video tag, this data is also provided by the playback-progress event
muteUnmutenonetoggle video sound on/off
mutenonedisable video sound (sets volume to 0)
unmutenoneenable video sound (sets volume to last value)
oneventName, listenerFnattaches a listener function to either the video tag or the player instance, the function will be run every time the event is fired, see events
onceeventName, listenerFnattaches a listener function to either the video tag or the player instance, the function will fire just on time, see events
pausenonestop video playback
playPausenonetoggle pause state on/off
playnonestart video playback
volumefloat numbersets the video volume, see volume configuration
getVolumefloat numbergets the video volume
getDurationnumbergets the video duration

Accessible properties

All properties are read-only:

property nametypedescription
readybooleanhelps identify when the video/ad is rendered and ready for playback
dataReadybooleanhelps identify when the player has all the data it needs to render the video and all listeners have been set
configobjectcurrent player's configuration, see Options
playerDOM nodecurrent video tag, it is not recommended to interact directly with it, and instead rely on the player's methods, but is provided if necessary
dimensionsobjectcurrent player dimensions
VPAIDWrapperobjectwrapper that allows direct interaction with a VPAID creative if available, it is not recommended to interact directly with it, but it is possible if necessary

Events

Listen for any <video> tag events or GgEzVp events:

ggEzVpInstance.on('play', myPlayListener);
ggEzVpInstance.on('playback-progress', myPlaybackListener);

Listen to them only once:

ggEzVpInstance.once('play', myPlayListener);
ggEzVpInstance.once('playback-progress', myProgressListener);

The player also emits custom events to extend the video tag behavior:

event namedescriptionpayload
data-readyemitted when a source for the video is received, either by configuration or after asynchronous VAST parsingundefined
playback-progressemitted when the video currentTime changes{ remainingTime, readableTime, duration, currentTime, fancyCurrentTime, fancyDuration }
player-clickemitted when clicks are detected inside the container elementclick event
pre-destroyemitted before removing listeners and the container nodeundefined
readyemitted when the class is ready for playbackundefined
resizeemitted when video tag changes either width or height{ width, height }
skipemitted when the skip button is pressedundefined
expandemitted when the fullscreen is toggledboolean isFullscreen
erroremitted when player encounters an errorerror message or object

Custom events are provided by Nano Events

VAST

VAST 3.0 is supported, thanks to dailymotion/vast-client-js for the playback of a single Linear Creative. If a VPAID is detected, it will be loaded and executed, otherwise, the player will track and emit all the events in the VAST tag.

VPAID

The player is capable of playing VPAID 2.0 if the src is a VAST tag and isVAST is set to true in the configuration. Player events will not be set immediately, instead they will be stored and attached after the VPAID has emitted the onAdLoaded event.

Event mapping

All VPAID events are emmitted, additionally, some of them will also fire a custom event:

VPAID event nameGgEzVp event name
AdLoadeddata-ready
AdStartedplay
AdPlayingplay
AdVideoStartplay
AdPausedpause
AdStoppedended
AdRemainingTimeChangeplayback-progress
AdDurationChangeplayback-progress
AdVideoFirstQuartileplayback-progress
AdVideoMidpointplayback-progress
AdVideoThirdQuartileplayback-progress
AdVideoCompleteplayback-progress
AdErrorerror

It is encouraged to use these events mapped by the player, but if you require listening to other events, all VPAID events are emitted as well with exception of the AdRemainingTimeChange event (use playback-progress instead). All data is retrieved from the VPAID creative, not the video tag itself.

Development

yarn install to install dependencies

yarn start to fire dev server and node watcher, the server can be accessed at localhost:8080, and the demo at localhost:8080/demo

See scripts section of package.json for all available scripts