Player Class
Constructor
Player
()
Example:
Using the Player
Add the following script on your HTML:
<head>
<script type="text/javascript" src="http://cdn.clappr.io/latest/clappr.min.js"></script>
</head>
Now, create the player:
<body>
<div id="player"></div>
<script>
var player = new Clappr.Player({source: "http://your.video/here.mp4", parentId: "#player"});
</script>
</body>
Item Index
Methods
Properties
Events
- CONTAINER_BITRATE
- CONTAINER_HIGHDEFINITIONUPDATE
- CONTAINER_LOADEDMETADATA
- CONTAINER_LOADEDTEXTTRACK
- CONTAINER_MEDIACONTROL_HIDE
- CONTAINER_MEDIACONTROL_SHOW
- CONTAINER_OPTIONS_CHANGE
- CONTAINER_PLAYBACKSTATE
- CONTAINER_PROGRESS
- CONTAINER_READY
- CONTAINER_SEEK
- CONTAINER_SETTINGSUPDATE
- CONTAINER_STATE_BUFFERFULL
- CONTAINER_STATE_BUFFERING
- CONTAINER_TIMEUPDATE
- CORE_CONTAINERS_CREATED
- CORE_FULLSCREEN
- CORE_OPTIONS_CHANGE
- CORE_READY
- CORE_SCREEN_ORIENTATION_CHANGED
- MEDIACONTROL_CONTAINERCHANGED
- MEDIACONTROL_FULLSCREEN
- MEDIACONTROL_HIDE
- MEDIACONTROL_MOUSELEAVE_SEEKBAR
- MEDIACONTROL_MOUSEMOVE_SEEKBAR
- MEDIACONTROL_NOTPLAYING
- MEDIACONTROL_PLAYING
- MEDIACONTROL_SHOW
- PLAYBACK_BITRATE
- PLAYBACK_BUFFERFULL
- PLAYBACK_BUFFERING
- PLAYBACK_DVR
- PLAYBACK_ENDED
- PLAYBACK_ERROR
- PLAYBACK_HIGHDEFINITIONUPDATE
- PLAYBACK_LEVEL_SWITCH_END
- PLAYBACK_LEVEL_SWITCH_START
- PLAYBACK_LEVELS_AVAILABLE
- PLAYBACK_LOADEDMETADATA
- PLAYBACK_PAUSE
- PLAYBACK_PLAY
- PLAYBACK_PLAY_INTENT
- PLAYBACK_PLAYBACKSTATE
- PLAYBACK_PROGRESS
- PLAYBACK_READY
- PLAYBACK_SETTINGSUPDATE
- PLAYBACK_STOP
- PLAYBACK_TIMEUPDATE
- PLAYER_ENDED
- PLAYER_ERROR
- PLAYER_FULLSCREEN
- PLAYER_PAUSE
- PLAYER_PLAY
- PLAYER_READY
- PLAYER_RESIZE
- PLAYER_SEEK
- PLAYER_STOP
- PLAYER_TIMEUPDATE
- PLAYER_VOLUMEUPDATE
Methods
attachTo
-
element
You can use this method to attach the player to a given element. You don't need to do this when you specify it during the player instantiation passing the parentId
param.
Parameters:
-
element
Objecta given element.
Returns:
itself
configure
-
options
enables to configure a player after its creation
Parameters:
-
options
Objectall the options to change in form of a javascript object
Returns:
itself
consent
()
Player
Gives user consent to playback. Required by mobile device after a click event before Player.load().
Returns:
itself
constructor
-
options
Player's constructor
You might pass the options object to build the player.
var options = {source: "http://example.com/video.mp4", param1: "val1"};
var player = new Clappr.Player(options);
Parameters:
-
options
ObjectData options to build a player instance
-
[width]
Number optionalplayer's width default:
640
-
[height]
Number optionalplayer's height default:
360
-
[parentId]
String optionalthe id of the element on the page that the player should be inserted into
-
[parent]
Object optionala reference to a dom element that the player should be inserted into
-
[source]
String optionalThe media source URL, or {source: <
-
[sources]
Object optionalAn array of media source URL's, or an array of {source: <
>, mimeType: < >} -
[autoPlay]
Boolean optionalautomatically play after page load default:
false
-
[loop]
Boolean optionalautomatically replay after it ends default:
false
-
[chromeless]
Boolean optionalplayer acts in chromeless mode default:
false
-
[allowUserInteraction]
Boolean optionalwhether or not the player should handle click events when in chromeless mode default:
false
on desktops browsers,true
on mobile. -
[disableKeyboardShortcuts]
Boolean optionaldisable keyboard shortcuts. default:
false
.true
ifallowUserInteraction
isfalse
. -
[muted]
Boolean optionalstart the video muted default:
false
-
[mimeType]
String optionaladd
mimeType: "application/vnd.apple.mpegurl"
if you need to use a url without extension. -
[actualLiveTime]
String optionalshow duration and seek time relative to actual time.
-
[actualLiveServerTime]
String optionalspecify server time as a string, format: "2015/11/26 06:01:03". This option is meant to be used with actualLiveTime.
-
[persistConfig]
Boolean optionalpersist player's settings (volume) through the same domain default:
true
-
[preload]
String optionalvideo will be preloaded according to
preload
attribute options default:'metadata'
-
[maxBufferLength]
Number optionalthe default behavior for the HLS playback is to keep buffering indefinitely, even on VoD. This replicates the behavior for progressive download, which continues buffering when pausing the video, thus making the video available for playback even on slow networks. To change this behavior use
maxBufferLength
where value is in seconds. -
[gaAccount]
String optionalenable Google Analytics events dispatch (play/pause/stop/buffering/etc) by adding your
gaAccount
-
[gaTrackerName]
String optionalbesides
gaAccount
you can optionally, pass your favorite trackerName asgaTrackerName
-
[mediacontrol]
Object optionalcustomize control bar colors, example:
mediacontrol: {seekbar: "#E113D3", buttons: "#66B2FF"}
-
[hideMediaControl]
Boolean optionalcontrol media control auto hide default:
true
-
[hideVolumeBar]
Boolean optionalwhen embedded with width less than 320, volume bar will hide. You can force this behavior for all sizes by adding
true
default:false
-
[watermark]
String optionalput
watermark: 'http://url/img.png'
on your embed parameters to automatically add watermark on your video. You can customize corner position by defining position parameter. Positions can bebottom-left
,bottom-right
,top-left
andtop-right
. -
[watermarkLink]
String optionalwatermarkLink: 'http://example.net/'
- define URL to open when the watermark is clicked. If not provided watermark will not be clickable. -
[disableVideoTagContextMenu]
Boolean optionaldisables the context menu (right click) on the video element if a HTML5Video playback is used.
-
[autoSeekFromUrl]
Boolean optionalAutomatically seek to the seconds provided in the url (e.g example.com?t=100) default:
true
-
[exitFullscreenOnEnd]
Boolean optionalAutomatically exit full screen when the media finishes. default:
true
-
[poster]
String optionaldefine a poster by adding its address
poster: 'http://url/img.png'
. It will appear after video embed, disappear on play and go back when user stops the video. -
[playbackNotSupportedMessage]
String optionaldefine a custom message to be displayed when a playback is not supported.
-
[events]
Object optionalSpecify listeners which will be registered with their corresponding player events. E.g. onReady -> "PLAYER_READY", onTimeUpdate -> "PLAYER_TIMEUPDATE"
-
getCurrentTime
()
Number
the current time in seconds.
Returns:
current time (in seconds) of the current source
getDuration
()
Number
the duration time in seconds.
Returns:
duration time (in seconds) of the current source
getPlugin
-
name
get a plugin by its name.
Parameters:
-
name
Stringof the plugin.
Returns:
the plugin instance
Example:
var poster = player.getPlugin('poster');
poster.hidePlayButton();
getStartTimeOffset
()
Number
The time that "0" now represents relative to when playback started. For a stream with a sliding window this will increase as content is removed from the beginning.
Returns:
time (in seconds) that time "0" represents.
getVolume
()
Number
Get the volume for the current video
Returns:
volume should be a number between 0 and 100, 0 being mute and 100 the max volume.
isPlaying
()
Boolean
checks if the player is playing.
Returns:
true
if the current source is playing, otherwise false
listenTo
-
obj
-
name
-
callback
-
context
listen to an event indefinitely for a given obj
Example:
this.listenTo(this.core.playback, Events.PLAYBACK_PAUSE, this.callback)
listenToOnce
-
obj
-
name
-
callback
-
context
listen to an event once for a given obj
Example:
this.listenToOnce(this.core.playback, Events.PLAYBACK_PAUSE, this.callback)
load
-
sources
-
mimeType
-
[autoPlay=false]
loads a new source.
Parameters:
Returns:
itself
off
-
name
-
callback
-
context
stop listening to an event
on
-
name
-
callback
-
context
listen to an event indefinitely, if you want to stop you need to call off
once
-
name
-
callback
-
context
listen to an event only once
resize
-
size
resizes the current player canvas.
Parameters:
-
size
Objectshould be a literal object with
height
andwidth
.
Returns:
itself
Example:
player.resize({height: 360, width: 640})
seek
-
time
seeks the current video (source
). For example, player.seek(120)
will seek to second 120 (2minutes) of the current video.
Parameters:
-
time
Numbershould be a number between 0 and the video duration.
Returns:
itself
seekPercentage
-
time
seeks the current video (source
). For example, player.seek(50)
will seek to the middle of the current video.
Parameters:
-
time
Numbershould be a number between 0 and 100.
Returns:
itself
setParentId
-
parentId
Specify a parentId
to the player.
Parameters:
-
parentId
Stringthe element parent id.
Returns:
itself
setVolume
-
volume
Set the volume for the current video (source
).
Parameters:
-
volume
Numbershould be a number between 0 and 100, 0 being mute and 100 the max volume.
Returns:
itself
stopListening
-
obj
-
name
-
callback
stop listening an event for a given object
Properties
buffering
Boolean
Determine if the playback is having to buffer in order for playback to be smooth. (i.e if a live stream is playing smoothly, this will be false)
eventsMapping
Object
An events map that allows the user to add custom callbacks in player's options.
Events
CONTAINER_BITRATE
Fired when the container updates its bitrate
Event Payload:
-
bitrate
ObjectData bitrate object
-
[bandwidth]
Number optionalbitrate bandwidth when it's available
-
[width]
Number optionalplayback width (ex: 720, 640, 1080)
-
[height]
Number optionalplayback height (ex: 240, 480, 720)
-
[level]
Number optionalplayback level when it's available, it could be just a map for width (0 => 240, 1 => 480, 2 => 720)
-
CONTAINER_HIGHDEFINITIONUPDATE
Fired when container updates its video quality
Event Payload:
-
isHD true
Booleanwhen is on HD, false otherwise
CONTAINER_LOADEDMETADATA
Fired when the container loaded its metadata
CONTAINER_LOADEDTEXTTRACK
Fired when a text track is loaded and available on container for display
CONTAINER_MEDIACONTROL_HIDE
Fired when the media control hides
CONTAINER_MEDIACONTROL_SHOW
Fired when the media control shows
CONTAINER_OPTIONS_CHANGE
Fired when the options were changed for the container
CONTAINER_PLAYBACKSTATE
Fired when the container internal state changes
CONTAINER_PROGRESS
Fired when the container is downloading the media
CONTAINER_READY
Fired when the container is ready
CONTAINER_SEEK
Fired when the container seeks the video
Event Payload:
-
time
Numberthe current time in seconds
CONTAINER_SETTINGSUPDATE
Fired when the container changes any settings (volume, seek and etc)
CONTAINER_STATE_BUFFERFULL
Fired when the container filled the buffer
CONTAINER_STATE_BUFFERING
Fired when container is buffering
CONTAINER_TIMEUPDATE
Fired when the time is updated on container
CORE_CONTAINERS_CREATED
Fired when the containers are created
CORE_FULLSCREEN
Fired when the fullscreen state change
Event Payload:
-
whether
Booleanor not the player is on fullscreen mode
CORE_OPTIONS_CHANGE
Fired when the options were changed for the core
CORE_READY
Fired after creating containers, when the core is ready
CORE_SCREEN_ORIENTATION_CHANGED
Fired when the screen orientation has changed. This event is trigger only for mobile devices.
MEDIACONTROL_CONTAINERCHANGED
Fired when the container was changed
MEDIACONTROL_FULLSCREEN
Fired when the player enters/exit on fullscreen
MEDIACONTROL_HIDE
Fired when the media control hides
MEDIACONTROL_MOUSELEAVE_SEEKBAR
Fired when mouse leaves the seekbar
Event Payload:
-
event the
Objectjavascript event
MEDIACONTROL_MOUSEMOVE_SEEKBAR
Fired when mouse enters on the seekbar
Event Payload:
-
event the
Objectjavascript event
MEDIACONTROL_NOTPLAYING
Fired when the media is not being played
MEDIACONTROL_PLAYING
Fired when the media is being played
MEDIACONTROL_SHOW
Fired when the media control shows
PLAYBACK_BITRATE
Fired when playback updates its bitrate
Event Payload:
-
bitrate
ObjectData bitrate object
-
[bandwidth]
Number optionalbitrate bandwidth when it's available
-
[width]
Number optionalplayback width (ex: 720, 640, 1080)
-
[height]
Number optionalplayback height (ex: 240, 480, 720)
-
[level]
Number optionalplayback level when it's available, it could be just a map for width (0 => 240, 1 => 480, 2 => 720)
-
PLAYBACK_BUFFERFULL
Fired when the playback has enough in the buffer to be able to play smoothly, after previously being unable to do this.
This corresponds to the playback buffering
property being
false
.
PLAYBACK_BUFFERING
Fired when the playback starts having to buffer because playback can currently not be smooth.
This corresponds to the playback buffering
property being
true
.
PLAYBACK_DVR
Fired when DVR becomes enabled/disabled.
Event Payload:
-
state
Booleantrue if dvr enabled
PLAYBACK_ENDED
Fired when the media for a playback ends.
Event Payload:
-
name
Stringthe name of the playback
PLAYBACK_ERROR
Fired if an error occurs in the playback.
PLAYBACK_HIGHDEFINITIONUPDATE
Fired when playback updates its video quality
Event Payload:
-
isHD true
Booleanwhen is on HD, false otherwise
PLAYBACK_LEVEL_SWITCH_END
Fired when the playback ends the level switch
PLAYBACK_LEVEL_SWITCH_START
Fired when the playback starts to switch level
PLAYBACK_LEVELS_AVAILABLE
Fired when the playback has its levels
PLAYBACK_LOADEDMETADATA
Fired when playback loaded its metadata
PLAYBACK_PAUSE
Fired when the media for a playback pauses.
PLAYBACK_PLAY
Fired when the media for a playback starts playing.
This is not necessarily when the user requests play()
The media may have to buffer first.
I.e. isPlaying()
might return true
before this event is fired,
because isPlaying()
represents the intended state.
PLAYBACK_PLAY_INTENT
Fired when user requests play()
PLAYBACK_PLAYBACKSTATE
Fired when playback internal state changes
PLAYBACK_PROGRESS
Fired when the playback is downloading the media
PLAYBACK_READY
Fired when playback is ready
PLAYBACK_SETTINGSUPDATE
Fired when playback changes any settings (volume, seek and etc)
PLAYBACK_STOP
Fired when the media for a playback is stopped.
PLAYBACK_TIMEUPDATE
Fired when the time is updated on playback
PLAYER_ENDED
Fired when player ends the video
PLAYER_FULLSCREEN
Fired when player changes its fullscreen state
Event Payload:
-
whether
Booleanor not the player is on fullscreen mode
PLAYER_PAUSE
Fired when player pauses
PLAYER_PLAY
Fired when player starts to play
PLAYER_READY
Fired when the player is ready on startup
PLAYER_RESIZE
Fired when player resizes
Event Payload:
-
currentSize
Objectan object with the current size
PLAYER_SEEK
Fired when player seeks the video
Event Payload:
-
time
Numberthe current time in seconds
PLAYER_STOP
Fired when player stops
PLAYER_TIMEUPDATE
Fired when the time is updated on player
PLAYER_VOLUMEUPDATE
Fired when player updates its volume
Event Payload:
-
volume
Numberthe current volume