Commit 50c682e4 by David Ormsbee

Merge pull request #583 from MITx/rocha/master

[#35065403] Lets video player work if subtitles cannot be loaded
parents b62d9535 aa063d57
class @VideoCaption extends Subview class @VideoCaption extends Subview
initialize: ->
@loaded = false
bind: -> bind: ->
$(window).bind('resize', @resize) $(window).bind('resize', @resize)
@$('.hide-subtitles').click @toggle @$('.hide-subtitles').click @toggle
...@@ -24,6 +27,8 @@ class @VideoCaption extends Subview ...@@ -24,6 +27,8 @@ class @VideoCaption extends Subview
@captions = captions.text @captions = captions.text
@start = captions.start @start = captions.start
@loaded = true
if onTouchBasedDevice() if onTouchBasedDevice()
$('.subtitles li').html "Caption will be displayed when you start playing the video." $('.subtitles li').html "Caption will be displayed when you start playing the video."
else else
...@@ -47,37 +52,40 @@ class @VideoCaption extends Subview ...@@ -47,37 +52,40 @@ class @VideoCaption extends Subview
@rendered = true @rendered = true
search: (time) -> search: (time) ->
min = 0 if @loaded
max = @start.length - 1 min = 0
max = @start.length - 1
while min < max
index = Math.ceil((max + min) / 2) while min < max
if time < @start[index] index = Math.ceil((max + min) / 2)
max = index - 1 if time < @start[index]
if time >= @start[index] max = index - 1
min = index if time >= @start[index]
min = index
return min return min
play: -> play: ->
@renderCaption() unless @rendered if @loaded
@playing = true @renderCaption() unless @rendered
@playing = true
pause: -> pause: ->
@playing = false if @loaded
@playing = false
updatePlayTime: (time) -> updatePlayTime: (time) ->
# This 250ms offset is required to match the video speed if @loaded
time = Math.round(Time.convert(time, @currentSpeed, '1.0') * 1000 + 250) # This 250ms offset is required to match the video speed
newIndex = @search time time = Math.round(Time.convert(time, @currentSpeed, '1.0') * 1000 + 250)
newIndex = @search time
if newIndex != undefined && @currentIndex != newIndex
if @currentIndex if newIndex != undefined && @currentIndex != newIndex
@$(".subtitles li.current").removeClass('current') if @currentIndex
@$(".subtitles li[data-index='#{newIndex}']").addClass('current') @$(".subtitles li.current").removeClass('current')
@$(".subtitles li[data-index='#{newIndex}']").addClass('current')
@currentIndex = newIndex
@scrollCaption() @currentIndex = newIndex
@scrollCaption()
resize: => resize: =>
@$('.subtitles').css maxHeight: @captionHeight() @$('.subtitles').css maxHeight: @captionHeight()
......
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