Commit df31b311 by Valera Rozuvan

Fixed bug when switching speeds in YouTube HTML5 player.

parent baf6bbe3
......@@ -15,7 +15,7 @@ class @VideoAlpha
else
@videoType = "html5"
@parseVideoSources @el.data('mp4-source'), @el.data('webm-source'), @el.data('ogg-source')
@speeds = ['0.75', '1.0', '1.25', '1.5']
@speeds = ['0.75', '1.0', '1.25', '1.50']
sub = @el.data('sub')
if (typeof sub isnt "string") or (sub.length is 0)
sub = ""
......
......@@ -194,6 +194,7 @@ this.HTML5Video = (function () {
// currently doing.
this.video = this.videoEl[0];
this.playerState = HTML5Video.PlayerState.UNSTARTED;
// this.callStateChangeCallback();
// Attach a 'click' event on the <video> element. It will cause the video to pause/play.
this.videoEl.on('click', function (event) {
......@@ -227,7 +228,7 @@ this.HTML5Video = (function () {
_this.video.currentTime = _this.start;
if ($.isFunction(_this.config.events.onReady) === true) {
_this.config.events.onReady({});
_this.config.events.onReady(null);
}
}, false);
......
......@@ -68,9 +68,14 @@ class @VideoPlayerAlpha extends SubviewAlpha
onReady: @onReady
onStateChange: @onStateChange
else if @video.videoType is 'youtube'
prev_player_type = $.cookie('prev_player_type')
if prev_player_type == 'html5'
youTubeId = @video.videos['1.0']
else
youTubeId = @video.youtubeId()
@player = new YT.Player @video.id,
playerVars: @playerVars
videoId: @video.youtubeId()
videoId: youTubeId
events:
onReady: @onReady
onStateChange: @onStateChange
......@@ -85,6 +90,8 @@ class @VideoPlayerAlpha extends SubviewAlpha
at: 'top center'
onReady: (event) =>
if @video.videoType is 'html5'
@player.setPlaybackRate @video.speed
unless onTouchBasedDevice()
$('.video-load-complete:first').data('video').player.play()
......@@ -94,7 +101,14 @@ class @VideoPlayerAlpha extends SubviewAlpha
when @PlayerState.UNSTARTED
if @video.videoType is "youtube"
availableSpeeds = @player.getAvailablePlaybackRates()
prev_player_type = $.cookie('prev_player_type')
if availableSpeeds.length > 1
if prev_player_type == 'youtube'
$.cookie('prev_player_type', 'html5', expires: 3650, path: '/')
@onSpeedChange null, '1.0'
else if prev_player_type != 'html5'
$.cookie('prev_player_type', 'html5', expires: 3650, path: '/')
baseSpeedSubs = @video.videos["1.0"]
$.each @video.videos, (index, value) ->
delete _this.video.videos[index]
......@@ -102,8 +116,15 @@ class @VideoPlayerAlpha extends SubviewAlpha
$.each availableSpeeds, (index, value) ->
_this.video.videos[value.toFixed(2).replace(/\.00$/, ".0")] = baseSpeedSubs
_this.video.speeds.push value.toFixed(2).replace(/\.00$/, ".0")
@speedControl.reRender @video.speeds
@speedControl.reRender @video.speeds, @video.speed
@video.videoType = 'html5'
@video.setSpeed $.cookie('video_speed')
@player.setPlaybackRate @video.speed
else
if prev_player_type != 'youtube'
$.cookie('prev_player_type', 'youtube', expires: 3650, path: '/')
@onUnstarted()
when @PlayerState.PLAYING
@onPlay()
......
......@@ -29,12 +29,15 @@ class @VideoSpeedControlAlpha extends SubviewAlpha
@$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link))
@setSpeed @currentSpeed
reRender: (newSpeeds) ->
reRender: (newSpeeds, currentSpeed) ->
@$('.video_speeds').empty()
@$('.video_speeds li').removeClass('active')
@speeds = newSpeeds
$.each @speeds, (index, speed) =>
link = $('<a>').attr(href: "#").html("#{speed}x")
@$('.video_speeds').prepend($('<li>').attr('data-speed', speed).html(link))
listItem = $('<li>').attr('data-speed', speed).html(link);
listItem.addClass('active') if speed is currentSpeed
@$('.video_speeds').prepend listItem
@$('.video_speeds a').click @changeVideoSpeed
changeVideoSpeed: (event) =>
......
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