1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-02 06:32:07 +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(){
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();
}
});

View File

@ -163,25 +163,22 @@ _V_.Player = _V_.Component.extend({
// And append playback element in player div.
loadTech: function(techName, source){
this.triggerEvent("loadingtech");
// Pause and remove current playback technology
if (this.tech) {
this.removeTech(this.tech);
this.tech.destroy();
// Turn off any manual progress or timeupdate tracking
if (this.manualProgress) {
this.manualProgressOff()
}
if (this.manualProgress) { this.manualProgressOff(); }
if (this.manualTimeUpdates) {
this.manualTimeUpdatesOff()
}
if (this.manualTimeUpdates) { this.manualTimeUpdatesOff(); }
this.tech = false;
// 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
} else if (!this.tech && techName != "html5") {
this.removeTechElement(this.tag);
} else if (techName != "html5") {
this.el.removeChild(this.tag);
}
this.techName = techName;
@ -190,8 +187,8 @@ _V_.Player = _V_.Component.extend({
this.isReady = false;
var techReady = function(){
// Set up playback technology's event triggers
this.setupTriggers();
_V_.log("ready")
this.player.triggerReady();
// 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
// Add tech element to player div
if (this.techs[techName] === undefined) {
// Grab tech-specific options from player options and add source and parent element to use.
var techOptions = _V_.merge({ source: source, parentEl: this.el }, this.options[techName])
var techOptions = _V_.merge({ source: source }, this.options[techName])
this.techs[techName] = this.tech = new _V_[techName](this, techOptions);
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);
// Initialize tech instance
this.tech = new _V_[techName](this, techOptions);
this.tech.ready(techReady);
},
/* Fallbacks for unsupported event types
@ -394,7 +375,7 @@ _V_.Player.prototype.extend({
start = 0, end = this.values.bufferEnd = this.values.bufferEnd || 0,
timeRange;
if (buffered && buffered.length > 0 && buffered.end(0) > end) {
if (buffered && buffered.length > 0 && buffered.end(0) !== end) {
end = buffered.end(0);
// Storing values allows them be overridden by setBufferedFromProgress
this.values.bufferEnd = end;

View File

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