-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Return currentSource_.src instead of blob-urls in html5 tech #2232
Changes from 4 commits
930792c
9e16b91
b7c1641
940adfa
f83ba42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -495,6 +495,7 @@ vjs.MediaTechController.withSourceHandlers = function(Tech){ | |
*/ | ||
Tech.prototype.setSource = function(source){ | ||
var sh = Tech.selectSourceHandler(source); | ||
var tech = this; | ||
|
||
if (!sh) { | ||
// Fall back to a native source hander when unsupported sources are | ||
|
@@ -510,7 +511,14 @@ vjs.MediaTechController.withSourceHandlers = function(Tech){ | |
this.disposeSourceHandler(); | ||
this.off('dispose', this.disposeSourceHandler); | ||
|
||
this.currentSource_ = source; | ||
// Set currentSource_ asynchronously to simulate the media element's | ||
// asynchronous execution of the `resource selection algorithm` | ||
this.setTimeout(function () { | ||
if (source && source.src !== '') { | ||
tech.currentSource_ = source; | ||
} | ||
}, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice. If you use Adding async always makes me worried about edge cases we're not thinking of... I can't think of anything specific though so we could pull this in and see how it goes. @videojs/core-committers any final opinions on this (setting currentSrc asynchronously or not)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this matches |
||
|
||
this.sourceHandler_ = sh.handleSource(source, this); | ||
this.on('dispose', this.disposeSourceHandler); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,10 @@ test('should add the source hanlder interface to a tech', function(){ | |
|
||
// Pass a source through the source handler process of a tech instance | ||
tech.setSource(sourceA); | ||
|
||
// Increment clock since currentSource_ is set asynchronously | ||
this.clock.tick(1); | ||
|
||
strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored'); | ||
ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored'); | ||
|
||
|
@@ -250,4 +254,54 @@ test('should handle unsupported sources with the source hanlder API', function() | |
|
||
tech.setSource(''); | ||
ok(usedNative, 'native source handler was used when an unsupported source was set'); | ||
}); | ||
}); | ||
|
||
test('should emulate the video element\'s behavior for currentSrc when src is set', function(){ | ||
var mockPlayer = { | ||
off: this.noop, | ||
trigger: this.noop | ||
}; | ||
var sourceA = { src: 'foo.mp4', type: 'video/mp4' }; | ||
var sourceB = { src: '', type: 'video/mp4' }; | ||
|
||
// 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); | ||
|
||
// Create source handlers | ||
var handler = { | ||
canHandleSource: function(source){ | ||
return 'probably'; | ||
}, | ||
handleSource: function(s, t){return {};} | ||
}; | ||
|
||
Tech.registerSourceHandler(handler); | ||
|
||
// Pass a source through the source handler process of a tech instance | ||
tech.setSource(sourceA); | ||
|
||
// Test that currentSource_ is not immediately specified | ||
strictEqual(tech.currentSource_, undefined, 'sourceA was not stored immediately'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Given all the state to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation is backwards compatible with existing techs. Moving anything to MediaController either doesn't buy us code savings or requires potentially breaking changes which we shouldn't be making in VJS4. I agree that for VJS5 we should strongly consider moving much the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a breaking change and we feel this is useful, we should consider it quickly so we can add it to 5.0 before it's too late. Though, really, now would be the time to just iterate through the major versions quickly, once it settles down, we should move more carefully. |
||
|
||
this.clock.tick(1); | ||
|
||
// Test that currentSource_ is specified after yielding to the event loop | ||
strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored'); | ||
|
||
// Pass a source with an empty src | ||
tech.setSource(sourceB); | ||
|
||
// Test that currentSource_ is not immediately changed | ||
strictEqual(tech.currentSource_, sourceA, 'sourceB was not stored immediately'); | ||
|
||
this.clock.tick(1); | ||
|
||
// Test that currentSource_ is still unchanged | ||
strictEqual(tech.currentSource_, sourceA, 'sourceB was not stored if equal to the empty string'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should bind this method instead of using the
tech
variable.