Nation JavaScript Library v2

BasicYouTubePlayer

function
BasicYouTubePlayer()

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
preventInit {boolean: false} If true, the YouTube video will not actually be created until playVideo is called
loop {boolean: false} Video will infinitely loop if this is true
mute {boolean: false} If true, the video will be muted by default
mobileMode {boolean: false} If true, the browser's default controls will always show, and the video will not attempt to autoplay

Dependencies:

NATION.Utils
NATION.EventDispatcher

About:

Basic YouTube video player without custom controls

To immediately initiate a video, use the data attribute 'data-video' on the selector, and set this to the YouTube video's URL

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

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

Example

PLAYER_READY

property
BasicYouTubePlayer.prototype.PLAYER_READY

Event that's fired when the video can be played

VIDEO_PLAYING

property
BasicYouTubePlayer.prototype.VIDEO_PLAYING

Event that's fired when the video has started playing

VIDEO_PAUSED

property
BasicYouTubePlayer.prototype.VIDEO_PAUSED

Event that's fired when the video has been paused

VIDEO_COMPLETE

property
BasicYouTubePlayer.prototype.VIDEO_COMPLETE

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

PLAY_PROGRESS

property
BasicYouTubePlayer.prototype.PLAY_PROGRESS

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

LOAD_PROGRESS

property
BasicYouTubePlayer.prototype.LOAD_PROGRESS

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

FULL_SCREEN_ENTER

property
BasicYouTubePlayer.prototype.FULL_SCREEN_ENTER

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

FULL_SCREEN_EXIT

property
BasicYouTubePlayer.prototype.FULL_SCREEN_EXIT

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

playVideo

method
BasicYouTubePlayer.prototype.playVideo()

Play, or resume playing, the video

pauseVideo

method
BasicYouTubePlayer.prototype.pauseVideo()

Pause the video

mute

method
BasicYouTubePlayer.prototype.mute()

Mute the video's sound

unMute

method
BasicYouTubePlayer.prototype.unMute()

Unmute the video's sound

seekTo

method
BasicYouTubePlayer.prototype.seekTo()

Option name Type Description
time number

Time to seek the current video to (in seconds)

Seek video to a position

getCurrentTime

method
BasicYouTubePlayer.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
BasicYouTubePlayer.prototype.getPlayProgress()

Returns current progress percentage between 0 and 1

getVideoLoadedFraction

method
BasicYouTubePlayer.prototype.getVideoLoadedFraction()

Returns percentage of current video loaded between 0 and 1

getDuration

method
BasicYouTubePlayer.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
BasicYouTubePlayer.prototype.getDurationText()

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

getCurrentTimeText

method
BasicYouTubePlayer.prototype.getCurrentTimeText()

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

isReady

method
BasicYouTubePlayer.prototype.isReady()

Returns whether player can be used yet

isPlaying

method
BasicYouTubePlayer.prototype.isPlaying()

Returns if video is currently playing

enterFullScreen

method
BasicYouTubePlayer.prototype.enterFullScreen()

Enters full screen mode

exitFullScreen

method
BasicYouTubePlayer.prototype.exitFullScreen()

Exits full screen mode

playNewVideo

method
BasicYouTubePlayer.prototype.playNewVideo()

Play a new video (stops any currently playing)

getHasPlayTriggered

method
BasicYouTubePlayer.prototype.getHasPlayTriggered() ->boolean

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

rebuild

method
BasicYouTubePlayer.prototype.rebuild()

Rebuild the YouTube player

remove

method
BasicYouTubePlayer.prototype.remove()

Destroy the player completely