Skip to content

Commit

Permalink
Fixed setting the source to an empty string. Fixes videojs#1785
Browse files Browse the repository at this point in the history
  • Loading branch information
heff committed Feb 27, 2015
1 parent 06b8541 commit 91de025
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/js/media/media.js
Expand Up @@ -496,6 +496,16 @@ vjs.MediaTechController.withSourceHandlers = function(Tech){
Tech.prototype.setSource = function(source){
var sh = Tech.selectSourceHandler(source);

if (!sh) {
// Fall back to a native source hander when unsupported sources are
// deliberately set
if (Tech.nativeSourceHandler) {
sh = Tech.nativeSourceHandler;
} else {
vjs.log.error('No source hander found for the current source.');
}
}

// Dispose any existing source handler
this.disposeSourceHandler();
this.off('dispose', this.disposeSourceHandler);
Expand Down
22 changes: 22 additions & 0 deletions test/unit/media.js
Expand Up @@ -229,3 +229,25 @@ test('should add the source hanlder interface to a tech', function(){
tech.dispose();
ok(disposeCalled, 'the handler dispose method was called when the tech was disposed');
});

test('should handle unsupported sources with the source hanlder API', function(){
var mockPlayer = {
off: this.noop,
trigger: this.noop
};

// Define a new tech class
var Tech = videojs.MediaTechController.extend();
// Extend Tech with source handlers
vjs.MediaTechController.withSourceHandlers(Tech);
// Create an instance of Tech
var tech = new Tech(mockPlayer);

var usedNative;
Tech.nativeSourceHandler = {
handleSource: function(){ usedNative = true; }
};

tech.setSource('');
ok(usedNative, 'native source handler was used when an unsupported source was set');
});

0 comments on commit 91de025

Please sign in to comment.