Skip to content

Instantly share code, notes, and snippets.

@mplatts
Created September 8, 2015 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mplatts/01ba1ecabca668efc30b to your computer and use it in GitHub Desktop.
Save mplatts/01ba1ecabca668efc30b to your computer and use it in GitHub Desktop.
// Usage:
//
// var video = videojs('video_id');
// video.iframeSeek();
//
// To start the player at 30s
// $iframe[0].contentWindow.postMessage('startTime:30', '*')
//
(function(window, videojs) {
'use strict';
var plugin = function(options) {
var player = this;
window.addEventListener("message", function(evt) {
var msg = evt.data
if (msg.match(/^(.*)\:/)[1] == "startTime") {
var seek = parseInt(msg.match(/\:(.*)/)[1]);
if (seek) {
player.ready(function(){
player.currentTime(seek);
});
}
}
});
};
// register the plugin
videojs.plugin('iframeSeek', plugin);
})(window, window.videojs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment