1
0
mirror of https://github.com/videojs/video.js.git synced 2025-07-17 01:42:41 +02:00

Fixed tech switching.

Fixed an issue where bigplaybutton was throwing an error when not preloading.
Fixed a bufferring issue when tech switching.
This commit is contained in:
Steve Heffernan
2012-01-02 13:02:04 -08:00
parent 38cc63c530
commit 242ff4c68b
3 changed files with 49 additions and 52 deletions

6
src/controls.js vendored
View File

@ -167,7 +167,11 @@ _V_.BigPlayButton = _V_.Button.extend({
}, },
onClick: function(){ onClick: function(){
this.player.currentTime(0); // Go back to the beginning if big play button is showing at the end.
// Have to check for current time otherwise it might throw a 'not ready' error.
if(this.player.currentTime()) {
this.player.currentTime(0);
}
this.player.play(); this.player.play();
} }
}); });

View File

@ -163,25 +163,22 @@ _V_.Player = _V_.Component.extend({
// And append playback element in player div. // And append playback element in player div.
loadTech: function(techName, source){ loadTech: function(techName, source){
this.triggerEvent("loadingtech");
// Pause and remove current playback technology // Pause and remove current playback technology
if (this.tech) { if (this.tech) {
this.removeTech(this.tech);
this.tech.destroy();
// Turn off any manual progress or timeupdate tracking // Turn off any manual progress or timeupdate tracking
if (this.manualProgress) { if (this.manualProgress) { this.manualProgressOff(); }
this.manualProgressOff()
}
if (this.manualTimeUpdates) { if (this.manualTimeUpdates) { this.manualTimeUpdatesOff(); }
this.manualTimeUpdatesOff()
} this.tech = false;
// If the first time loading, HTML5 tag will exist but won't be initialized // If the first time loading, HTML5 tag will exist but won't be initialized
// So we need to remove it if we're not loading HTML5 // So we need to remove it if we're not loading HTML5
} else if (!this.tech && techName != "html5") { } else if (techName != "html5") {
this.removeTechElement(this.tag); this.el.removeChild(this.tag);
} }
this.techName = techName; this.techName = techName;
@ -190,8 +187,8 @@ _V_.Player = _V_.Component.extend({
this.isReady = false; this.isReady = false;
var techReady = function(){ var techReady = function(){
// Set up playback technology's event triggers _V_.log("ready")
this.setupTriggers();
this.player.triggerReady(); this.player.triggerReady();
// Manually track progress in cases where the browser/flash player doesn't report it. // Manually track progress in cases where the browser/flash player doesn't report it.
@ -205,28 +202,12 @@ _V_.Player = _V_.Component.extend({
} }
} }
// Initialize new tech if it hasn't been yet and load source // Grab tech-specific options from player options and add source and parent element to use.
// Add tech element to player div var techOptions = _V_.merge({ source: source, parentEl: this.el }, this.options[techName])
if (this.techs[techName] === undefined) {
var techOptions = _V_.merge({ source: source }, this.options[techName]) // Initialize tech instance
this.tech = new _V_[techName](this, techOptions);
this.techs[techName] = this.tech = new _V_[techName](this, techOptions); this.tech.ready(techReady);
this.tech.ready(techReady)
} else {
this.tech = this.techs[techName];
_V_.insertFirst(this.techs[techName].el, this.el);
this.src(source);
}
},
removeTech: function(tech){
this.removeTechElement(tech.el);
// TODO: Remove API listeners as well
},
removeTechElement: function(el){
this.el.removeChild(el);
}, },
/* Fallbacks for unsupported event types /* Fallbacks for unsupported event types
@ -394,7 +375,7 @@ _V_.Player.prototype.extend({
start = 0, end = this.values.bufferEnd = this.values.bufferEnd || 0, start = 0, end = this.values.bufferEnd = this.values.bufferEnd || 0,
timeRange; timeRange;
if (buffered && buffered.length > 0 && buffered.end(0) > end) { if (buffered && buffered.length > 0 && buffered.end(0) !== end) {
end = buffered.end(0); end = buffered.end(0);
// Storing values allows them be overridden by setBufferedFromProgress // Storing values allows them be overridden by setBufferedFromProgress
this.values.bufferEnd = end; this.values.bufferEnd = end;

View File

@ -9,9 +9,8 @@ _V_.PlaybackTech = _V_.Component.extend({
// player.triggerEvent("techready"); // player.triggerEvent("techready");
} }
// destroy: function(){},
// createElement: function(){}, // createElement: function(){},
// setupTriggers: function(){},
// removeTriggers: function(){}
}); });
// Create placeholder methods for each that warn when a method isn't supported by the current playback technology // Create placeholder methods for each that warn when a method isn't supported by the current playback technology
@ -54,27 +53,39 @@ _V_.html5 = _V_.PlaybackTech.extend({
} }
}); });
this.setupTriggers();
this.triggerReady(); this.triggerReady();
}, },
destroy: function(){
this.player.tag = false;
this.el.parentNode.removeChild(this.el);
},
createElement: function(){ createElement: function(){
var html5 = _V_.html5, var html5 = _V_.html5,
player = this.player, player = this.player,
// Reuse original tag for HTML5 playback technology element // If possible, reuse original tag for HTML5 playback technology element
el = player.tag, el = player.tag,
newEl; newEl;
// Check if this browser supports moving the element into the box. // Check if this browser supports moving the element into the box.
// On the iPhone video will break if you move the element, // On the iPhone video will break if you move the element,
// So we have to create a brand new element. // So we have to create a brand new element.
if (html5.supports.movingElementInDOM === false) { if (!el || html5.supports.movingElementInDOM === false) {
// If the original tag is still there, remove it.
if (el) {
player.el.removeChild(el);
}
newEl = _V_.createElement("video", { newEl = _V_.createElement("video", {
id: el.id, id: el.id || player.el.id + "_html5_api",
className: el.className className: el.className || "vjs-tech"
}); });
player.el.removeChild(el);
el = newEl; el = newEl;
_V_.insertFirst(el, player.el); _V_.insertFirst(el, player.el);
} }
@ -226,8 +237,9 @@ _V_.flash = _V_.PlaybackTech.extend({
init: function(player, options){ init: function(player, options){
this.player = player; this.player = player;
var placeHolder = this.el = _V_.createElement("div", { id: player.el.id + "_temp_flash" }), var source = options.source,
source = options.source, parentEl = options.parentEl,
placeHolder = this.el = _V_.createElement("div", { id: parentEl.id + "_temp_flash" }),
objId = player.el.id+"_flash_api", objId = player.el.id+"_flash_api",
playerOptions = player.options; playerOptions = player.options;
@ -268,17 +280,17 @@ _V_.flash = _V_.PlaybackTech.extend({
} }
// Add to box. // Add to box.
_V_.insertFirst(placeHolder, player.el); _V_.insertFirst(placeHolder, parentEl);
_V_.log(attributes)
swfobject.embedSWF(options.swf, placeHolder.id, "480", "270", "9.0.124", "", flashVars, params, attributes); swfobject.embedSWF(options.swf, placeHolder.id, "480", "270", "9.0.124", "", flashVars, params, attributes);
}, },
setupTriggers: function(){ destroy: function(){
// Using global onSWFEvent func to distribute events this.el.parentNode.removeChild(this.el);
}, },
// setupTriggers: function(){}, // Using global onSWFEvent func to distribute events
play: function(){ this.el.vjs_play(); }, play: function(){ this.el.vjs_play(); },
pause: function(){ this.el.vjs_pause(); }, pause: function(){ this.el.vjs_pause(); },
src: function(src){ src: function(src){
@ -369,7 +381,7 @@ _V_.flash.onSWFReady = function(currSwf){
// Get player from box // Get player from box
// On firefox reloads, el might already have a player // On firefox reloads, el might already have a player
var player = el.player || el.parentNode.player, var player = el.player || el.parentNode.player,
tech = player.techs["flash"]; tech = player.tech;
// Reference player on tech element // Reference player on tech element
el.player = player; el.player = player;