Commit ded745dc by J. Cliff Dyer

Add video copmletion handler to main player.

parent 5475e3ed
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
'video/09_events_plugin.js', 'video/09_events_plugin.js',
'video/09_events_bumper_plugin.js', 'video/09_events_bumper_plugin.js',
'video/09_poster.js', 'video/09_poster.js',
'video/99_completion.js',
'video/10_commands.js', 'video/10_commands.js',
'video/095_video_context_menu.js' 'video/095_video_context_menu.js'
], ],
...@@ -61,8 +62,8 @@ ...@@ -61,8 +62,8 @@
VideoStorage, initialize, FocusGrabber, VideoAccessibleMenu, VideoControl, VideoFullScreen, VideoStorage, initialize, FocusGrabber, VideoAccessibleMenu, VideoControl, VideoFullScreen,
VideoQualityControl, VideoProgressSlider, VideoVolumeControl, VideoSpeedControl, VideoCaption, VideoQualityControl, VideoProgressSlider, VideoVolumeControl, VideoSpeedControl, VideoCaption,
VideoPlayPlaceholder, VideoPlayPauseControl, VideoPlaySkipControl, VideoSkipControl, VideoBumper, VideoPlayPlaceholder, VideoPlayPauseControl, VideoPlaySkipControl, VideoSkipControl, VideoBumper,
VideoSaveStatePlugin, VideoEventsPlugin, VideoEventsBumperPlugin, VideoPoster, VideoCommands, VideoSaveStatePlugin, VideoEventsPlugin, VideoEventsBumperPlugin, VideoPoster,
VideoContextMenu VideoCompletionHandler, VideoCommands, VideoContextMenu
) { ) {
var youtubeXhr = null, var youtubeXhr = null,
oldVideo = window.Video; oldVideo = window.Video;
...@@ -75,7 +76,7 @@ ...@@ -75,7 +76,7 @@
mainVideoModules = [FocusGrabber, VideoControl, VideoPlayPlaceholder, mainVideoModules = [FocusGrabber, VideoControl, VideoPlayPlaceholder,
VideoPlayPauseControl, VideoProgressSlider, VideoSpeedControl, VideoVolumeControl, VideoPlayPauseControl, VideoProgressSlider, VideoSpeedControl, VideoVolumeControl,
VideoQualityControl, VideoFullScreen, VideoCaption, VideoCommands, VideoContextMenu, VideoQualityControl, VideoFullScreen, VideoCaption, VideoCommands, VideoContextMenu,
VideoSaveStatePlugin, VideoEventsPlugin], VideoSaveStatePlugin, VideoEventsPlugin, VideoCompletionHandler],
bumperVideoModules = [VideoControl, VideoPlaySkipControl, VideoSkipControl, bumperVideoModules = [VideoControl, VideoPlaySkipControl, VideoSkipControl,
VideoVolumeControl, VideoCaption, VideoCommands, VideoSaveStatePlugin, VideoEventsBumperPlugin], VideoVolumeControl, VideoCaption, VideoCommands, VideoSaveStatePlugin, VideoEventsBumperPlugin],
state = { state = {
...@@ -116,6 +117,7 @@ ...@@ -116,6 +117,7 @@
saveStateUrl: state.metadata.saveStateUrl saveStateUrl: state.metadata.saveStateUrl
}); });
if (bumperMetadata) { if (bumperMetadata) {
new VideoPoster(el, { new VideoPoster(el, {
poster: el.data('poster'), poster: el.data('poster'),
......
...@@ -8,20 +8,20 @@ ...@@ -8,20 +8,20 @@
* @param {Object} state The object containing the state of the video * @param {Object} state The object containing the state of the video
* @return {jquery Promise} * @return {jquery Promise}
*/ */
var CompletionListener = function(state) { var VideoCompletionHandler = function(state) {
if (!(this instanceof CompletionListener)) { if (!(this instanceof VideoCompletionHandler)) {
return new CompletionListener(state); return new VideoCompletionHandler(state);
} }
_.bindAll(this, 'play', 'pause', 'onClick', 'destroy'); _.bindAll(this, 'play', 'pause', 'onClick', 'destroy');
this.state = state; this.state = state;
this.state.completionListener = this; this.state.completionHandler = this;
this.initialize(); this.initialize();
return $.Deferred().resolve().promise(); return $.Deferred().resolve().promise();
}; };
CompletionListener.prototype = { VideoCompletionHandler.prototype = {
destroy: function() { destroy: function() {
this.el.remove(); this.el.remove();
this.state.el.off('destroy', this.destroy); this.state.el.off('destroy', this.destroy);
...@@ -30,20 +30,23 @@ ...@@ -30,20 +30,23 @@
/** Initializes the module. */ /** Initializes the module. */
initialize: function() { initialize: function() {
this.complete = False; this.complete = false;
this.lastValue = 1;
this.bindHandlers(); this.bindHandlers();
}, },
/** Bind any necessary function callbacks to DOM events. */ /** Bind any necessary function callbacks to DOM events. */
bindHandlers: function() { bindHandlers: function() {
this.state.el.on({ this.state.el.on({timeupdate: this.checkCompletion});
'timeupdate': this.checkCompletion,
});
}, },
/** Event handler to check if the video is complete, and submit a completion if it is */ /** Event handler to check if the video is complete, and submit a completion if it is */
checkCompletion: function(currentTime) { checkCompletion: function(currentTime) {
// Need to access runtime for this. // Need to access runtime for this.
if (currentTime != this.lastValue) {
console.warn("CURRENT TIME", currentTime);
this.lastValue = currentTime;
}
if (this.complete === false && currentTime > this.state.completeAfter) { if (this.complete === false && currentTime > this.state.completeAfter) {
this.complete = true; this.complete = true;
if (this.state.config.publishCompletionUrl) { if (this.state.config.publishCompletionUrl) {
...@@ -54,13 +57,13 @@ ...@@ -54,13 +57,13 @@
completion: 1.0 completion: 1.0
}) })
}); });
} else { } else {
console.warn("publishCompletionUrl not defined"); console.warn('publishCompletionUrl not defined');
} }
} }
} }
}; };
return CompletionListener; return VideoCompletionHandler;
}); });
}(RequireJS.define)); }(RequireJS.define));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment