diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index 6587f05899..a170075b68 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -2,6 +2,8 @@ class @Video constructor: (element) -> @el = $(element).find('.video') @id = @el.attr('id').replace(/video_/, '') + @start = @el.data('start') + @end = @el.data('end') @caption_data_dir = @el.data('caption-data-dir') @show_captions = @el.data('show-captions') == "true" window.player = null diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee index 9e5288b8a2..ec52d15874 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee @@ -36,17 +36,21 @@ class @VideoPlayer extends Subview @volumeControl = new VideoVolumeControl el: @$('.secondary-controls') @speedControl = new VideoSpeedControl el: @$('.secondary-controls'), speeds: @video.speeds, currentSpeed: @currentSpeed() @progressSlider = new VideoProgressSlider el: @$('.slider') - @debugger_1 + @playerVars = + controls: 0 + wmode: 'transparent' + rel: 0 + showinfo: 0 + enablejsapi: 1 + modestbranding: 1 + if @video.start + @playerVars.start = @video.start + if @video.end + # work in AS3, not HMLT5. but iframe use AS3 + @playerVars.end = @video.end + @player = new YT.Player @video.id, - playerVars: - controls: 0 - wmode: 'transparent' - rel: 0 - showinfo: 0 - enablejsapi: 1 - modestbranding: 1 - start: 10 - end: 20 + playerVars: @playerVars videoId: @video.youtubeId() events: onReady: @onReady diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index 9a22950ca8..801e70fd06 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -7,6 +7,9 @@ from pkg_resources import resource_string, resource_listdir from xmodule.x_module import XModule from xmodule.raw_module import RawDescriptor +import datetime +import time + log = logging.getLogger(__name__) @@ -33,6 +36,7 @@ class VideoModule(XModule): self.show_captions = xmltree.get('show_captions', 'true') self.source = self._get_source(xmltree) self.track = self._get_track(xmltree) + self.start_time, self.end_time = self._get_timeframe(xmltree) if instance_state is not None: state = json.loads(instance_state) @@ -42,11 +46,11 @@ class VideoModule(XModule): def _get_source(self, xmltree): # find the first valid source return self._get_first_external(xmltree, 'source') - + def _get_track(self, xmltree): # find the first valid track return self._get_first_external(xmltree, 'track') - + def _get_first_external(self, xmltree, tag): """ Will return the first valid element @@ -61,6 +65,23 @@ class VideoModule(XModule): break return result + def _get_timeframe(self, xmltree): + """ Converts 'from' and 'to' parameters in video tag to seconds. + If there are no parameters, returns empty string. """ + + def parse_time(s): + """Converts s in '12:34:45' format to seconds. If s is + None, returns empty string""" + if s is None: + return '' + else: + x = time.strptime(s, '%H:%M:%S') + return datetime.timedelta(hours=x.tm_hour, + minutes=x.tm_min, + seconds=x.tm_sec).total_seconds() + + return parse_time(xmltree.get('from')), parse_time(xmltree.get('to')) + def handle_ajax(self, dispatch, get): ''' Handle ajax calls to this video. @@ -98,11 +119,13 @@ class VideoModule(XModule): 'id': self.location.html_id(), 'position': self.position, 'source': self.source, - 'track' : self.track, + 'track': self.track, 'display_name': self.display_name, # TODO (cpennington): This won't work when we move to data that isn't on the filesystem 'data_dir': self.metadata['data_dir'], - 'show_captions': self.show_captions + 'show_captions': self.show_captions, + 'start': self.start_time, + 'end': self.end_time }) diff --git a/lms/templates/video.html b/lms/templates/video.html index 5c041d5c70..6e45a91c31 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -2,7 +2,9 @@