Skip to content

Commit

Permalink
MDL-58530 media_videojs: upgrade videojs to 5.18.4
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 7, 2017
1 parent bd99cb9 commit 4aaaabb
Show file tree
Hide file tree
Showing 12 changed files with 10,038 additions and 7,927 deletions.
2 changes: 1 addition & 1 deletion media/player/videojs/amd/build/Youtube-lazy.min.js

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions media/player/videojs/amd/build/video-lazy.min.js

Large diffs are not rendered by default.

123 changes: 70 additions & 53 deletions media/player/videojs/amd/src/Youtube-lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ THE SOFTWARE. */
}(this, function(videojs) {
'use strict';

var Tech = videojs.getComponent('Tech');
var _isOnMobile = videojs.browser.IS_IOS || videojs.browser.IS_ANDROID;
var Tech = videojs.getTech('Tech');

var Youtube = videojs.extend(Tech, {

Expand Down Expand Up @@ -77,7 +78,7 @@ THE SOFTWARE. */
this.el_.parentNode.className = this.el_.parentNode.className
.replace(' vjs-youtube', '')
.replace(' vjs-youtube-mobile', '');
this.el_.remove();
this.el_.parentNode.removeChild(this.el_);

//Needs to be called after the YouTube player is destroyed, otherwise there will be a null reference exception
Tech.prototype.dispose.call(this);
Expand Down Expand Up @@ -206,6 +207,14 @@ THE SOFTWARE. */
playerVars.theme = this.options_.theme;
}

// Allow undocumented options to be passed along via customVars
if (typeof this.options_.customVars !== 'undefined') {
var customVars = this.options_.customVars;
Object.keys(customVars).forEach(function(key) {
playerVars[key] = customVars[key];
});
}

this.activeVideoId = this.url ? this.url.videoId : null;
this.activeList = playerVars.list;

Expand All @@ -215,20 +224,30 @@ THE SOFTWARE. */
events: {
onReady: this.onPlayerReady.bind(this),
onPlaybackQualityChange: this.onPlayerPlaybackQualityChange.bind(this),
onPlaybackRateChange: this.onPlayerPlaybackRateChange.bind(this),
onStateChange: this.onPlayerStateChange.bind(this),
onError: this.onPlayerError.bind(this)
}
});
},

onPlayerReady: function() {
if (this.options_.muted) {
this.ytPlayer.mute();
}

var playbackRates = this.ytPlayer.getAvailablePlaybackRates();
if (playbackRates.length > 1) {
this.featuresPlaybackRate = true;
}

this.playerReady_ = true;
this.triggerReady();

if (this.playOnReady) {
this.play();
} else if (this.cueOnReady) {
this.ytPlayer.cueVideoById(this.url.videoId);
this.cueVideoById_(this.url.videoId);
this.activeVideoId = this.url.videoId;
}
},
Expand All @@ -237,6 +256,10 @@ THE SOFTWARE. */

},

onPlayerPlaybackRateChange: function() {
this.trigger('ratechange');
},

onPlayerStateChange: function(e) {
var state = e.data;

Expand All @@ -251,6 +274,7 @@ THE SOFTWARE. */
this.trigger('loadstart');
this.trigger('loadedmetadata');
this.trigger('durationchange');
this.trigger('ratechange');
break;

case YT.PlayerState.ENDED:
Expand Down Expand Up @@ -286,26 +310,55 @@ THE SOFTWARE. */

onPlayerError: function(e) {
this.errorNumber = e.data;
this.trigger('pause');
this.trigger('error');

this.ytPlayer.stopVideo();
},

error: function() {
var code = 1000 + this.errorNumber; // as smaller codes are reserved
switch (this.errorNumber) {
case 5:
return { code: 'Error while trying to play the video' };
return { code: code, message: 'Error while trying to play the video' };

case 2:
case 100:
return { code: 'Unable to find the video' };
return { code: code, message: 'Unable to find the video' };

case 101:
case 150:
return { code: 'Playback on other Websites has been disabled by the video owner.' };
return {
code: code,
message: 'Playback on other Websites has been disabled by the video owner.'
};
}

return { code: code, message: 'YouTube unknown error (' + this.errorNumber + ')' };
},

loadVideoById_: function(id) {
var options = {
videoId: id
};
if (this.options_.start) {
options.startSeconds = this.options_.start;
}
if (this.options_.end) {
options.endEnd = this.options_.end;
}
this.ytPlayer.loadVideoById(options);
},

return { code: 'YouTube unknown error (' + this.errorNumber + ')' };
cueVideoById_: function(id) {
var options = {
videoId: id
};
if (this.options_.start) {
options.startSeconds = this.options_.start;
}
if (this.options_.end) {
options.endEnd = this.options_.end;
}
this.ytPlayer.cueVideoById(options);
},

src: function(src) {
Expand Down Expand Up @@ -358,7 +411,7 @@ THE SOFTWARE. */
}
} else if (this.activeVideoId !== this.url.videoId) {
if (this.isReady_) {
this.ytPlayer.cueVideoById(this.url.videoId);
this.cueVideoById_(this.url.videoId);
this.activeVideoId = this.url.videoId;
} else {
this.cueOnReady = true;
Expand Down Expand Up @@ -402,7 +455,7 @@ THE SOFTWARE. */
if (this.activeVideoId === this.url.videoId) {
this.ytPlayer.playVideo();
} else {
this.ytPlayer.loadVideoById(this.url.videoId);
this.loadVideoById_(this.url.videoId);
this.activeVideoId = this.url.videoId;
}
} else {
Expand Down Expand Up @@ -463,24 +516,11 @@ THE SOFTWARE. */
},

seekable: function () {
if(!this.ytPlayer || !this.ytPlayer.getVideoLoadedFraction) {
return {
length: 0,
start: function() {
throw new Error('This TimeRanges object is empty');
},
end: function() {
throw new Error('This TimeRanges object is empty');
}
};
if(!this.ytPlayer) {
return videojs.createTimeRange();
}
var end = this.ytPlayer.getDuration();

return {
length: this.ytPlayer.getDuration(),
start: function() { return 0; },
end: function() { return end; }
};
return videojs.createTimeRange(0, this.ytPlayer.getDuration());
},

onSeeked: function() {
Expand All @@ -504,7 +544,6 @@ THE SOFTWARE. */
}

this.ytPlayer.setPlaybackRate(suggestedRate);
this.trigger('ratechange');
},

duration: function() {
Expand Down Expand Up @@ -559,24 +598,12 @@ THE SOFTWARE. */

buffered: function() {
if(!this.ytPlayer || !this.ytPlayer.getVideoLoadedFraction) {
return {
length: 0,
start: function() {
throw new Error('This TimeRanges object is empty');
},
end: function() {
throw new Error('This TimeRanges object is empty');
}
};
return videojs.createTimeRange();
}

var end = this.ytPlayer.getVideoLoadedFraction() * this.ytPlayer.getDuration();
var bufferedEnd = this.ytPlayer.getVideoLoadedFraction() * this.ytPlayer.getDuration();

return {
length: this.ytPlayer.getDuration(),
start: function() { return 0; },
end: function() { return end; }
};
return videojs.createTimeRange(0, bufferedEnd);
},

// TODO: Can we really do something with this on YouTUbe?
Expand Down Expand Up @@ -626,8 +653,6 @@ THE SOFTWARE. */
return (e === 'video/youtube');
};

var _isOnMobile = videojs.browser.IS_IOS || useNativeControlsOnAndroid();

Youtube.parseUrl = function(url) {
var result = {
videoId: null
Expand Down Expand Up @@ -701,14 +726,6 @@ THE SOFTWARE. */
head.appendChild(style);
}

function useNativeControlsOnAndroid() {
var stockRegex = window.navigator.userAgent.match(/applewebkit\/(\d*).*Version\/(\d*.\d*)/i);
//True only Android Stock Browser on OS versions 4.X and below
//where a Webkit version and a "Version/X.X" String can be found in
//user agent.
return videojs.browser.IS_ANDROID && videojs.browser.ANDROID_VERSION < 5 && stockRegex && stockRegex[2] > 0;
}

Youtube.apiReadyQueue = [];

loadScript('https://www.youtube.com/iframe_api', apiLoaded);
Expand Down
Loading

0 comments on commit 4aaaabb

Please sign in to comment.