Commit ded745dc by J. Cliff Dyer

Add video copmletion handler to main player.

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