Nation JavaScript Library v2

BasicVideoPlayer

function
BasicVideoPlayer()

Option name Type Description
selector domelement_or_querystring_or_jqueryobject

The element containing the .js-player or .player element within which the video will be created

options object

Object containing the settings for this video player controls {boolean: false} If true, the browser's default controls will be shown
autoPlay {boolean: false} If true, the video will automatically start playing as soon as enough data has been downloaded
loop {boolean: false} Video will infinitely loop if this is true
mute {boolean: false} If true, the video will be muted by default
preload {boolean: false} If true, the 'preload' attribute will be set on the created video tag. Usually on desktop this will work, but mobile browsers intentionally ignore this to protec the user's data
mobileMode {boolean: false} If true, the browser's default controls will always show, and the video will not attempt to autoplay
poster {string: ""} The URL to the poster image to display at the start of the video

Dependencies:

NATION.Utils
NATION.EventDispatcher

About:

Basic HTML5 video player without custom controls

Supports h264, webM, and ogg video formats

API has been structured to allow this class to be interchangeable with the BasicYouTubePlayer

Can be used with NATION.MediaControls to create a full player

Example

PLAYER_READY

property
BasicVideoPlayer.prototype.PLAYER_READY

Event that's fired when the video can be played

VIDEO_PLAYING

property
BasicVideoPlayer.prototype.VIDEO_PLAYING

Event that's fired when the video has started playing

VIDEO_PAUSED

property
BasicVideoPlayer.prototype.VIDEO_PAUSED

Event that's fired when the video has been paused

VIDEO_COMPLETE

property
BasicVideoPlayer.prototype.VIDEO_COMPLETE

Event that fires when the video reaches the end and stops playing

PLAY_PROGRESS

property
BasicVideoPlayer.prototype.PLAY_PROGRESS

Event that's fired each time the video's current time changes

LOAD_PROGRESS

property
BasicVideoPlayer.prototype.LOAD_PROGRESS

Event that's fired each time video data has been downloaded

FULL_SCREEN_ENTER

property
BasicVideoPlayer.prototype.FULL_SCREEN_ENTER

Event that's fired when the player enters full screen mode

FULL_SCREEN_EXIT

property
BasicVideoPlayer.prototype.FULL_SCREEN_EXIT

Event that's fired when the player exits full screen mode

playVideo

method
BasicVideoPlayer.prototype.playVideo()

Play, or resume playing, the video

pauseVideo

method
BasicVideoPlayer.prototype.pauseVideo()

Pause the video

mute

method
BasicVideoPlayer.prototype.mute()

Mute the video's sound

unMute

method
BasicVideoPlayer.prototype.unMute()

Unmute the video's sound

seekTo

method
BasicVideoPlayer.prototype.seekTo()

Option name Type Description
time number

Time to seek the current video to (in seconds)

Seek video to a position

getCurrentTime

method
BasicVideoPlayer.prototype.getCurrentTime()

Option name Type Description
milliseconds number

If true, this method returns the current time in milliseconds

Returns current play position (in seconds)

getPlayProgress

method
BasicVideoPlayer.prototype.getPlayProgress()

Returns current progress percentage between 0 and 1

getVideoLoadedFraction

method
BasicVideoPlayer.prototype.getVideoLoadedFraction()

Returns percentage of current video loaded between 0 and 1

getDuration

method
BasicVideoPlayer.prototype.getDuration()

Option name Type Description
milliseconds number

If true, this method returns the duration in milliseconds

Returns duration of current video (in seconds)

getDurationText

method
BasicVideoPlayer.prototype.getDurationText()

Returns string with duration of video in 0:00:00 format

getCurrentTimeText

method
BasicVideoPlayer.prototype.getCurrentTimeText()

Returns string with current time in 0:00:00 format

isReady

method
BasicVideoPlayer.prototype.isReady()

Returns whether player can be used yet

isPlaying

method
BasicVideoPlayer.prototype.isPlaying()

Returns if video is currently playing

enterFullScreen

method
BasicVideoPlayer.prototype.enterFullScreen()

Enters full screen mode

exitFullScreen

method
BasicVideoPlayer.prototype.exitFullScreen()

Exits full screen mode

playNewVideo

method
BasicVideoPlayer.prototype.playNewVideo()

Play a new video (stops any currently playing)

getHasPlayTriggered

method
BasicVideoPlayer.prototype.getHasPlayTriggered() ->boolean

Returns true if this video has started playing yet. This is useful for mobile devices on data connections

rebuild

method
BasicVideoPlayer.prototype.rebuild()

Rebuild the player completely, stopping the current video and removing it from the DOM

remove

method
BasicVideoPlayer.prototype.remove()

Remove player from DOM