From 9e8a31065eec9fc2ae8b00dfc49ea8398ece4a3a Mon Sep 17 00:00:00 2001 From: Matt Osborn Date: Tue, 1 Jul 2014 10:46:16 +0100 Subject: [PATCH] adding a currentType method to get current source type if known --- src/js/exports.js | 1 + src/js/player.js | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/js/exports.js b/src/js/exports.js index 11ae06948..b517a41ae 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -70,6 +70,7 @@ goog.exportProperty(vjs.Component.prototype, 'buildCSSClass', vjs.Component.prot // Need to export ended to ensure it's not removed by CC, since it's not used internally goog.exportProperty(vjs.Player.prototype, 'ended', vjs.Player.prototype.ended); +goog.exportProperty(vjs.Player.prototype, 'currentType', vjs.Player.prototype.currentType); goog.exportSymbol('videojs.MediaLoader', vjs.MediaLoader); goog.exportSymbol('videojs.TextTrackDisplay', vjs.TextTrackDisplay); diff --git a/src/js/player.js b/src/js/player.js index cb6798943..8049d88eb 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -275,6 +275,7 @@ vjs.Player.prototype.loadTech = function(techName, source){ var techOptions = vjs.obj.merge({ 'source': source, 'parentEl': this.el_ }, this.options_[techName.toLowerCase()]); if (source) { + this.srcType_ = source.type; if (source.src == this.cache_.src && this.cache_.currentTime > 0) { techOptions['startTime'] = this.cache_.currentTime; } @@ -1065,6 +1066,17 @@ vjs.Player.prototype.selectSource = function(sources){ return false; }; +vjs.Player.prototype.setSource = function(source, type) { + this.srcType_ = type; + this.techCall('src', source); + if (this.options_['preload'] == 'auto') { + this.load(); + } + if (this.options_['autoplay']) { + this.play(); + } +}; + /** * The source function updates the video source * @@ -1131,7 +1143,7 @@ vjs.Player.prototype.src = function(source){ } else if (source instanceof Object) { if (window['videojs'][this.techName]['canPlaySource'](source)) { - this.src(source.src); + this.setSource(source.src, source.type); } else { // Send through tech loop to check for a compatible technology. this.src([source]); @@ -1144,16 +1156,10 @@ vjs.Player.prototype.src = function(source){ if (!this.isReady_) { this.ready(function(){ - this.src(source); + this.setSource(source); }); } else { - this.techCall('src', source); - if (this.options_['preload'] == 'auto') { - this.load(); - } - if (this.options_['autoplay']) { - this.play(); - } + this.setSource(source); } } @@ -1172,6 +1178,10 @@ vjs.Player.prototype.currentSrc = function(){ return this.techGet('currentSrc') || this.cache_.src || ''; }; +vjs.Player.prototype.currentType = function(){ + return this.srcType_ || ''; +}; + // Attributes/Options vjs.Player.prototype.preload = function(value){ if (value !== undefined) {