Commit 20c9a8af by Adam

Merge pull request #6510 from smarnach/safari-video-speed

Work around a Youtube API bug that causes Safari to ignore the stored speed
parents 9e7b916f daaf22a9
......@@ -86,7 +86,7 @@ function (HTML5Video, Resizer) {
// via the 'state' object. Much easier to work this way - you don't
// have to do repeated jQuery element selects.
function _initialize(state) {
var youTubeId, player;
var youTubeId, player, userAgent;
// The function is called just once to apply pre-defined configurations
// by student before video starts playing. Waits until the video's
......@@ -96,6 +96,16 @@ function (HTML5Video, Resizer) {
$(window).on('unload', state.saveState);
if (!state.isFlashMode() && state.speed != '1.0') {
// Work around a bug in the Youtube API that causes videos to
// play at normal speed rather than at the configured speed in
// Safari. Setting the playback rate to 1.0 *after* playing
// started and then to the actual value tricks the player into
// picking up the speed setting.
if (state.browserIsSafari && state.isYoutubeType()) {
state.videoPlayer.setPlaybackRate(1.0, false);
}
state.videoPlayer.setPlaybackRate(state.speed, true);
}
});
......@@ -125,19 +135,13 @@ function (HTML5Video, Resizer) {
state.videoPlayer.playerVars.html5 = 1;
}
// There is a bug which prevents YouTube API to correctly set the speed
// to 1.0 from another speed in Firefox when in HTML5 mode. There is a
// fix which basically reloads the video at speed 1.0 when this change
// is requested (instead of simply requesting a speed change to 1.0).
// This has to be done only when the video is being watched in Firefox.
// We need to figure out what browser is currently executing this code.
//
// TODO: Check the status of
// http://code.google.com/p/gdata-issues/issues/detail?id=4654
// When the YouTube team fixes the API bug, we can remove this
// temporary bug fix.
state.browserIsFirefox = navigator.userAgent
.toLowerCase().indexOf('firefox') > -1;
// Detect the current browser for several browser-specific work-arounds.
userAgent = navigator.userAgent.toLowerCase();
state.browserIsFirefox = userAgent.indexOf('firefox') > -1;
state.browserIsChrome = userAgent.indexOf('chrome') > -1;
// Chrome includes both "Chrome" and "Safari" in the user agent.
state.browserIsSafari = (userAgent.indexOf('safari') > -1 &&
!state.browserIsChrome);
if (state.videoType === 'html5') {
state.videoPlayer.player = new HTML5Video.Player(state.el, {
......@@ -356,6 +360,18 @@ function (HTML5Video, Resizer) {
time = this.videoPlayer.currentTime,
methodName, youtubeId;
// There is a bug which prevents YouTube API to correctly set the speed
// to 1.0 from another speed in Firefox when in HTML5 mode. There is a
// fix which basically reloads the video at speed 1.0 when this change
// is requested (instead of simply requesting a speed change to 1.0).
// This has to be done only when the video is being watched in Firefox.
// We need to figure out what browser is currently executing this code.
//
// TODO: Check the status of
// http://code.google.com/p/gdata-issues/issues/detail?id=4654
// When the YouTube team fixes the API bug, we can remove this
// temporary bug fix.
// If useCueVideoById is true it will reload video again.
// Used useCueVideoById to fix the issue video not playing if we change
// the speed before playing the video.
......
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