diff --git a/src/js/media/media.js b/src/js/media/media.js index 34605bc508..0a7cd59ad5 100644 --- a/src/js/media/media.js +++ b/src/js/media/media.js @@ -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); diff --git a/test/unit/media.js b/test/unit/media.js index e4a44045cf..bdf1da641a 100644 --- a/test/unit/media.js +++ b/test/unit/media.js @@ -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'); +}); \ No newline at end of file