Commit baf6bbe3 by Valera Rozuvan

Finalized HTML5 YouTube player inbrowser speed changes.

parent 143217d6
...@@ -25,7 +25,7 @@ class @VideoAlpha ...@@ -25,7 +25,7 @@ class @VideoAlpha
"1.0": sub "1.0": sub
"1.25": sub "1.25": sub
"1.5": sub "1.5": sub
@setSpeed($.cookie('video_speed')) @setSpeed $.cookie('video_speed')
$("#video_#{@id}").data('video', this).addClass('video-load-complete') $("#video_#{@id}").data('video', this).addClass('video-load-complete')
if @show_captions is true if @show_captions is true
@hide_captions = $.cookie('hide_captions') == 'true' @hide_captions = $.cookie('hide_captions') == 'true'
...@@ -47,7 +47,7 @@ class @VideoAlpha ...@@ -47,7 +47,7 @@ class @VideoAlpha
youtubeId: (speed)-> youtubeId: (speed)->
@videos[speed || @speed] @videos[speed || @speed]
VideoAlpha::parseVideos = (videos) -> parseVideos: (videos)->
return false if (typeof videos isnt "string") or (videos.length is 0) return false if (typeof videos isnt "string") or (videos.length is 0)
@videos = {} @videos = {}
_this = this _this = this
...@@ -58,7 +58,7 @@ class @VideoAlpha ...@@ -58,7 +58,7 @@ class @VideoAlpha
_this.videos[speed] = video[1] _this.videos[speed] = video[1]
true true
VideoAlpha::parseVideoSources = (mp4Source, webmSource, oggSource) -> parseVideoSources: (mp4Source, webmSource, oggSource)->
@html5Sources = @html5Sources =
mp4: null mp4: null
webm: null webm: null
...@@ -69,9 +69,9 @@ class @VideoAlpha ...@@ -69,9 +69,9 @@ class @VideoAlpha
parseSpeed: -> parseSpeed: ->
@speeds = ($.map @videos, (url, speed) -> speed).sort() @speeds = ($.map @videos, (url, speed) -> speed).sort()
@setSpeed($.cookie('video_speed')) @setSpeed $.cookie('video_speed')
VideoAlpha::setSpeed = (newSpeed) -> setSpeed: (newSpeed)->
if @speeds.indexOf(newSpeed) isnt -1 if @speeds.indexOf(newSpeed) isnt -1
@speed = newSpeed @speed = newSpeed
$.cookie "video_speed", "" + newSpeed, $.cookie "video_speed", "" + newSpeed,
...@@ -91,7 +91,7 @@ class @VideoAlpha ...@@ -91,7 +91,7 @@ class @VideoAlpha
getDuration: -> getDuration: ->
@metadata[@youtubeId()].duration @metadata[@youtubeId()].duration
VideoAlpha::log = (eventName) -> log: (eventName)->
logInfo = logInfo =
id: @id id: @id
code: @youtubeId() code: @youtubeId()
......
...@@ -94,19 +94,16 @@ class @VideoPlayerAlpha extends SubviewAlpha ...@@ -94,19 +94,16 @@ class @VideoPlayerAlpha extends SubviewAlpha
when @PlayerState.UNSTARTED when @PlayerState.UNSTARTED
if @video.videoType is "youtube" if @video.videoType is "youtube"
availableSpeeds = @player.getAvailablePlaybackRates() availableSpeeds = @player.getAvailablePlaybackRates()
console.log @video.videos
if availableSpeeds.length > 1 if availableSpeeds.length > 1
baseSpeedSubs = @video.videos["1.0"] baseSpeedSubs = @video.videos["1.0"]
$.each @video.videos, (index, value) -> $.each @video.videos, (index, value) ->
delete _this.video.videos[index] delete _this.video.videos[index]
@video.speeds = []
$.each availableSpeeds, (index, value) -> $.each availableSpeeds, (index, value) ->
_this.video.videos[value.toFixed(2).replace(/\.00$/, ".0")] = baseSpeedSubs _this.video.videos[value.toFixed(2).replace(/\.00$/, ".0")] = baseSpeedSubs
_this.video.speeds.push value.toFixed(2).replace(/\.00$/, ".0")
@speedControl.reRender() @speedControl.reRender @video.speeds
@video.videoType = 'html5'
console.log "UNSTARTED. available speeds = "
console.log availableSpeeds
@onUnstarted() @onUnstarted()
when @PlayerState.PLAYING when @PlayerState.PLAYING
@onPlay() @onPlay()
...@@ -162,12 +159,12 @@ class @VideoPlayerAlpha extends SubviewAlpha ...@@ -162,12 +159,12 @@ class @VideoPlayerAlpha extends SubviewAlpha
if @video.videoType is 'youtube' if @video.videoType is 'youtube'
@currentTime = Time.convert(@currentTime, parseFloat(@currentSpeed()), newSpeed) @currentTime = Time.convert(@currentTime, parseFloat(@currentSpeed()), newSpeed)
newSpeed = parseFloat(newSpeed).toFixed(2).replace /\.00$/, '.0' newSpeed = parseFloat(newSpeed).toFixed(2).replace /\.00$/, '.0'
@video.setSpeed(newSpeed) @video.setSpeed newSpeed
if @video.videoType is 'youtube' if @video.videoType is 'youtube'
if @video.show_captions is true if @video.show_captions is true
@caption.currentSpeed = newSpeed @caption.currentSpeed = newSpeed
if @video.videoType is 'html5' if @video.videoType is 'html5'
@player.setSpeed(newSpeed) @player.setPlaybackRate newSpeed
else if @video.videoType is 'youtube' else if @video.videoType is 'youtube'
if @isPlaying() if @isPlaying()
@player.loadVideoById(@video.youtubeId(), @currentTime) @player.loadVideoById(@video.youtubeId(), @currentTime)
......
...@@ -24,20 +24,14 @@ class @VideoSpeedControlAlpha extends SubviewAlpha ...@@ -24,20 +24,14 @@ class @VideoSpeedControlAlpha extends SubviewAlpha
<ol class="video_speeds"></ol> <ol class="video_speeds"></ol>
</div> </div>
""" """
$.each @speeds, (index, speed) => $.each @speeds, (index, speed) =>
link = $('<a>').attr(href: "#").html("#{speed}x") link = $('<a>').attr(href: "#").html("#{speed}x")
@$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link)) @$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link))
@setSpeed(@currentSpeed) @setSpeed @currentSpeed
reRender: (newSpeeds) -> reRender: (newSpeeds) ->
@$('.video_speeds').empty() @$('.video_speeds').empty()
@speeds = newSpeeds
@speeds newSpeeds
console.log "Changing speeds"
console.log @speeds
$.each @speeds, (index, speed) => $.each @speeds, (index, speed) =>
link = $('<a>').attr(href: "#").html("#{speed}x") link = $('<a>').attr(href: "#").html("#{speed}x")
@$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link)) @$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link))
......
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