Commit df31b311 by Valera Rozuvan

Fixed bug when switching speeds in YouTube HTML5 player.

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