Slate Embedded Player SDK allows websites to control the embedded Slate Player with JavaScript and relays the DOM events from inside the iframe to the parent window.
Check our demo
Include the slate.player.min.js
file in your website and gain control over the embedded player (see Usage section for more info).
jQuery 1.6+ is required (but will potentially work with older versions as well).
All modern browsers including Internet Explorer 8+ are supported (thanks to window.postMessage()
implementation).
There are multiple ways to include this SDK on your website:
You can include this SDK directly from the GitHub CDN:
<script type="text/javascript" src="//slate-app.github.io/player/slate.player.min.js"></script>
You can install this SDK as a Bower component.
$ bower install slate-player
And then include in your page:
<script type="text/javascript" src="/path/to/bower_components/slate-player/slate.player.min.js"></script>
If none of the above work for you, just download slate.player.min.js
from this repository and save it somewhere on your server, and then include it on your website:
<script type="text/javascript" src="/path/to/slate.player.min.js"></script>
After including the JS file on your page your embedded players will start triggering DOM events out of the box, without any additional configuration. See the DOM Events section for more info.
It will also register a jQuery plugin .slatePlayer()
that will expose programmatic API with which you can control the player behavior.
All events from the original Slate Player bubble up to your website from inside the iframe. They are triggered on the embedding iframe and you can listen for them e.g. using jQuery's .on()
method:
$('#player').on('resume', function(ev, currentClip) {
console.log('clip ' + currentClip.title + ' was resumed');
});
Currently, the list of events is (called with the following additional parameters):
initialized
- when player has been initialized,load
withcurrentClip
- when the player is ready,error
withcurrentClip, error
- when error occurs,finish
withcurrentClip
- when clip finished playing,mute
withcurrentClip
- when the player has been muted,pause
withcurrentClip
- when the player was paused,resume
withcurrentClip
- when the player was resumed,stop
withcurrentClip
- when the player was stopped,beforeseek
withcurrentClip, position
- just before seeking happens,fullscreen
withcurrentClip
- when entered fullscreen mode,fullscreen-exit
withcurrentClip
- when left fullscreen mode,progress
withcurrentClip, position
- when video is playing, roughly every 250ms,seek
withcurrentClip, position
- when seeking,speed
withcurrentClip, speed
- when playback speed has changed,volume
withcurrentClip, level
- when volume level has changed.
You can control the player via its JavaScript API accessible as a jQuery plugin. To call a method pass its name as the 1st argument of .slatePlayer()
method on the embedded player element, e.g.:
$('#player').slatePlayer('volume', 0.4);
Following methods are available (where $player
in these examples is a jQuery object wrapping the embedded iframe, e.g. var $player = $('#player')
):
$player.slatePlayer('load', clip)
- load a clip to the player whereclip
is an object containing clip data from Slate$player.slatePlayer('play', index)
- playindex
position from the loaded playlist, if the player was initialized with a playlist (TBD)$player.slatePlayer('stop')
- stop playback$player.slatePlayer('pause')
- pause playback$player.slatePlayer('resume')
- resume playback$player.slatePlayer('mute')
- toggle mute/unmute$player.slatePlayer('next')
- jump to next item in the playlist$player.slatePlayer('prev')
- jump to previous item in the playlist$player.slatePlayer('seek', time)
- seek to specifiedtime
in seconds$player.slatePlayer('seekTo', position)
- seek to specified position where 1 = 10%, 2 = 20%, 3 = 30%, etc$player.slatePlayer('speed', speed)
- play at the specifiedspeed
where 1 = 100%$player.slatePlayer('toggle')
- toggle pause/resume the playback$player.slatePlayer('volume', volume)
- set specifiedvolume
None of these methods return any values.
Please report any issues using this repository's GitHub issues.