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

Store unload promise on player #613

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
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

Andy Hochhaus <[email protected]>
Chad Assareh <[email protected]>
Chris Fillmore <[email protected]>
Costel Madalin Grecu <[email protected]>
Donato Borrello <[email protected]>
Esteban Dosztal <[email protected]>
Expand Down
46 changes: 37 additions & 9 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ shaka.Player = function(video, opt_dependencyInjector) {
/** @private {Promise} */
this.mediaSourceOpen_ = null;

/** @private {Promise} */
this.unloadPromise_ = null;

/** @private {shaka.media.Playhead} */
this.playhead_ = null;

Expand Down Expand Up @@ -378,14 +381,14 @@ shaka.Player.probeSupport = function() {
*/
shaka.Player.prototype.load = function(manifestUri, opt_startTime,
opt_manifestParserFactory) {
var unloadPromise = this.unload();
this.unload();
var loadChain = new shaka.util.CancelableChain();
this.loadChain_ = loadChain;
this.dispatchEvent(new shaka.util.FakeEvent('loading'));

return loadChain.then(function() {
return unloadPromise;
}).then(function() {
return this.unloadPromise_;
}.bind(this)).then(function() {

goog.asserts.assert(this.networkingEngine_, 'Must not be destroyed');
return shaka.media.ManifestParser.getFactory(
Expand Down Expand Up @@ -753,24 +756,49 @@ shaka.Player.prototype.isBuffering = function() {
* @export
*/
shaka.Player.prototype.unload = function() {
if (this.destroyed_) return Promise.resolve();
if (this.unloadPromise_) {
// An unload is currently in progress. Do not initiate another one.
return this.unloadPromise_;
}

if (this.destroyed_) {
// No unloading necessary.
return Promise.resolve();
}

this.dispatchEvent(new shaka.util.FakeEvent('unloading'));

if (this.loadChain_) {
// A load is in progress. Cancel it, then reset the streaming system.
var interrupt = new shaka.util.Error(
shaka.util.Error.Category.PLAYER,
shaka.util.Error.Code.LOAD_INTERRUPTED);
return this.loadChain_.cancel(interrupt)
.then(this.resetStreaming_.bind(this));
return this.createUnloadPromise_(this.loadChain_.cancel(interrupt)
.then(this.resetStreaming_.bind(this)));
} else {
// No loads or unloads are in progress.
// Just reset the streaming system if needed.
return this.resetStreaming_();
// No loads are in progress. Just reset the streaming system if needed.
return this.createUnloadPromise_(this.resetStreaming_());
}
};


/**
* Create an unload promise and store it on the player until unloading
* is complete.
* @private
* @param {!Promise} unloadProcess Unloading steps to perform before destroying
* the unload promise.
* @return {!Promise}
*/
shaka.Player.prototype.createUnloadPromise_ = function(unloadProcess) {
Copy link
Member

Choose a reason for hiding this comment

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

Since you're passing in an unresolved Promise chain, and to keep terminology consistent with other parts of this file, change "unloadProcess" to "unloadChain" or "unloadPromiseChain".

this.unloadPromise_ = unloadProcess.then(function() {
this.unloadPromise_ = null;
}.bind(this));

return this.unloadPromise_;
};


/**
* Gets the current effective playback rate. If using trick play, it will
* return the current trick play rate; otherwise, it will return the video
Expand Down