Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed setting the source to an empty string #1905

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/js/media/media.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handler*

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');
});