From b5bd7a697f63dd164825680db75d5a7888c1bcd8 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Fri, 1 Feb 2013 16:18:03 +0200 Subject: [PATCH] Added start and end time support. --- .../js/src/videoalpha/display/html5_video.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js b/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js index 5ae936776c..1623b1b5eb 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js @@ -71,6 +71,20 @@ this.HTML5Video = (function () { return; } + this.start = 0; + this.end = null; + if (config.hasOwnProperty('playerVars') === true) { + this.start = parseFloat(config.playerVars.start); + if ((isFinite(this.start) !== true) || (this.start < 0)) { + this.start = 0; + } + + this.end = parseFloat(config.playerVars.end); + if ((isFinite(this.end) !== true) || (this.end < this.start)) { + this.end = null; + } + } + sourceStr = { 'mp4': ' ', 'webm': ' ', @@ -129,6 +143,14 @@ this.HTML5Video = (function () { this.video.addEventListener('canplay', function () { _this.playerState = HTML5Video.PlayerState.PAUSED; + if (_this.start > _this.video.duration) { + _this.start = 0; + } + if ((_this.end === null) || (_this.end > _this.video.duration)) { + _this.end = _this.video.duration; + } + _this.video.currentTime = _this.start; + if ($.isFunction(_this.config.events.onReady) === true) { _this.config.events.onReady({}); } @@ -160,6 +182,20 @@ this.HTML5Video = (function () { }); } }, false); + this.video.addEventListener('timeupdate', function (data) { + console.log('[timeupdate]'); + console.log(_this.video.currentTime); + if (_this.video.end > _this.video.currentTime) { + console.log('_this.video.end >= _this.video.currentTime -> pausing video'); + _this.playerState = HTML5Video.PlayerState.PAUSED; + + if ($.isFunction(_this.config.events.onStateChange) === true) { + _this.config.events.onStateChange({ + 'data': _this.playerState + }); + } + } + }, false); this.videoEl.appendTo(this.el.find('.video-player div')); }