Skip to content

Commit

Permalink
The base media tech class now checks the networkState at init to dete…
Browse files Browse the repository at this point in the history
…rmine if loadstart should be manually fired.

Previously this was only done in the HTML5 tech, but Flash needs it as well. This relies on videojs/video-js-swf#106.

Also removed the 'not implemented' warnings from the media tech functions. I think there's a better way we can help tech authors here, and it was blocking the ability to check if a function was implemented for real.

Fixes videojs#1300, fixes videojs#1341
  • Loading branch information
heff authored and paullryan committed Jul 17, 2014
1 parent 285dffb commit 7171fc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
10 changes: 4 additions & 6 deletions src/js/media/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ vjs.Html5 = vjs.MediaTechController.extend({

var source = options['source'];

// If the element source is already set, we may have missed the loadstart event, and want to trigger it.
// We don't want to set the source again and interrupt playback.
if (source && this.el_.currentSrc === source.src && this.el_.networkState > 0) {
player.trigger('loadstart');
// Otherwise set the source if one was provided.
} else if (source) {
// set the source if one was provided
if (source && this.el_.currentSrc !== source.src) {
this.el_.src = source.src;
}

Expand Down Expand Up @@ -247,6 +243,8 @@ vjs.Html5.prototype.defaultMuted = function(){ return this.el_.defaultMuted; };
vjs.Html5.prototype.playbackRate = function(){ return this.el_.playbackRate; };
vjs.Html5.prototype.setPlaybackRate = function(val){ this.el_.playbackRate = val; };

vjs.Html5.prototype.networkState = function(){ return this.el_.networkState; };

/* HTML5 Support Testing ---------------------------------------------------- */

vjs.Html5.isSupported = function(){
Expand Down
29 changes: 11 additions & 18 deletions src/js/media/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){
this.ready(activateControls);
player.on('controlsenabled', activateControls);
player.on('controlsdisabled', deactivateControls);

// if we're loading the playback object after it has started loading or playing the
// video (often with autoplay on) then the loadstart event has already fired and we
// need to fire it manually because many things rely on it.
// Long term we might consider how we would do this for other events like 'canplay'
// that may also have fired.
this.ready(function(){
if (this.networkState && this.networkState() > 0) {
this.player().trigger('loadstart');
}
});
};

vjs.MediaTechController.prototype.addControlsListeners = function(){
Expand Down Expand Up @@ -161,21 +172,3 @@ vjs.MediaTechController.prototype.features = {
};

vjs.media = {};

/**
* List of default API methods for any MediaTechController
* @type {String}
*/
vjs.media.ApiMethods = 'play,pause,paused,currentTime,setCurrentTime,duration,buffered,volume,setVolume,muted,setMuted,width,height,supportsFullScreen,enterFullScreen,src,load,currentSrc,preload,setPreload,autoplay,setAutoplay,loop,setLoop,error,networkState,readyState,seeking,initialTime,startOffsetTime,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks,defaultPlaybackRate,playbackRate,mediaGroup,controller,controls,defaultMuted'.split(',');
// Create placeholder methods for each that warn when a method isn't supported by the current playback technology

function createMethod(methodName){
return function(){
throw new Error('The "'+methodName+'" method is not available on the playback technology\'s API');
};
}

for (var i = vjs.media.ApiMethods.length - 1; i >= 0; i--) {
var methodName = vjs.media.ApiMethods[i];
vjs.MediaTechController.prototype[vjs.media.ApiMethods[i]] = createMethod(methodName);
}

0 comments on commit 7171fc0

Please sign in to comment.