-
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
setSrc clears currentSource_ after loadstart #3285
Changes from 4 commits
06dcc61
8d89829
132e107
47873df
f10fc92
84810c2
64be2ab
43aac04
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 |
---|---|---|
|
@@ -814,18 +814,44 @@ Tech.withSourceHandlers = function(_Tech){ | |
if (this.currentSource_) { | ||
this.clearTracks(['audio', 'video']); | ||
} | ||
this.currentSource_ = source; | ||
|
||
if (sh !== _Tech.nativeSourceHandler) { | ||
|
||
this.currentSource_ = source; | ||
|
||
// Catch if someone replaced the src without calling setSource. | ||
// If they do, set currentSource_ to null and dispose our source handler. | ||
this.off(this.el_, 'loadstart', _Tech.prototype.firstLoadStartListener_); | ||
this.off(this.el_, 'loadstart', _Tech.prototype.successiveLoadStartListener_); | ||
this.one(this.el_, 'loadstart', _Tech.prototype.firstLoadStartListener_); | ||
|
||
} | ||
|
||
this.sourceHandler_ = sh.handleSource(source, this, this.options_); | ||
this.on('dispose', this.disposeSourceHandler); | ||
|
||
return this; | ||
}; | ||
|
||
/* | ||
* Clean up any existing source handler | ||
*/ | ||
_Tech.prototype.disposeSourceHandler = function(){ | ||
// On the first loadstart after setSource | ||
_Tech.prototype.firstLoadStartListener_ = function() { | ||
this.one(this.el_, 'loadstart', _Tech.prototype.successiveLoadStartListener_); | ||
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. Why use one() if you want the successiveLoadStartListener_ to run on every subsequent loadstart? 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. It's because |
||
}; | ||
|
||
// On successive loadstarts when setSource has not been called again | ||
_Tech.prototype.successiveLoadStartListener_ = function() { | ||
this.currentSource_ = null; | ||
this.disposeSourceHandler(); | ||
this.one(this.el_, 'loadstart', _Tech.prototype.successiveLoadStartListener_); | ||
}; | ||
|
||
/* | ||
* Clean up any existing source handler | ||
*/ | ||
_Tech.prototype.disposeSourceHandler = function() { | ||
if (this.sourceHandler_ && this.sourceHandler_.dispose) { | ||
this.off(this.el_, 'loadstart', _Tech.prototype.firstLoadStartListener_); | ||
this.off(this.el_, 'loadstart', _Tech.prototype.successiveLoadStartListener_); | ||
this.sourceHandler_.dispose(); | ||
} | ||
}; | ||
|
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.
I'm not a fan of using event handler registration as instance-level state. The current set of registered event handlers are difficult to introspect and control flow is harder to trace. I don't see any logical issues with this code so we can move ahead with this but in general, I think adding an instance variable is preferable to this kind of solution.