Skip to content

Commit

Permalink
Change a ContentInitializer dispose method to stop
Browse files Browse the repository at this point in the history
This was done as it makes more sense to have an "idle" state after
stopping than disposing (in the latter case, we would have to add
something like the "disposed" state) and as it may be more portable to
allow re-using a ContentInitializer later, which however for now hasn't
any real case.
  • Loading branch information
peaBerberian committed Mar 26, 2024
1 parent b4859f8 commit fa03b7d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main_thread/api/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
currentContentCanceller.signal,
);
currentContentCanceller.signal.register(() => {
initializer.dispose();
initializer.stop();
});

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main_thread/init/directfile_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ export default class DirectFileContentInitializer extends ContentInitializer {
/**
* Stop content and free all resources linked to this `ContentIntializer`.
*/
public dispose(): void {
public stop(): void {
this._initCanceller.cancel();
this._initCanceller = new TaskCanceller();
this.state = ContentInitializerState.Idle;
this.trigger("stateChange", this.state);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main_thread/init/media_source_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,13 @@ export default class MediaSourceContentInitializer extends ContentInitializer {
* Stop content and free all resources linked to this
* `MediaSourceContentInitializer`.
*/
public dispose(): void {
public stop(): void {
if (this._contentMetadata?.type === "preparing") {
this._contentMetadata.reject(new Error("The content has been disposed"));
}
this._contentMetadata = null;
this._initCanceller.cancel();
this._initCanceller = new TaskCanceller();
this.state = ContentInitializerState.Idle;
this.trigger("stateChange", this.state);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main_thread/init/multi_thread_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,9 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
});
}

public dispose(): void {
public stop(): void {
this._initCanceller.cancel();
this._initCanceller = new TaskCanceller();
if (this._currentContentInfo !== null) {
this._currentContentInfo.mainThreadMediaSource?.dispose();
this._currentContentInfo = null;
Expand Down
6 changes: 4 additions & 2 deletions src/main_thread/init/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export abstract class ContentInitializer extends EventEmitter<IContentInitialize

/**
* Stop playing the content linked to this `ContentInitializer` on the
* `HTMLMediaElement` linked to it and dispose of every resources taken while
* `HTMLMediaElement` linked to it and free every resources taken while
* trying to do so.
*
* The content could be then restarted through a `start` call.
*/
public abstract dispose(): void;
public abstract stop(): void;
}

/** List of "states" in which a `ContentInitializer` may be in. */
Expand Down

0 comments on commit fa03b7d

Please sign in to comment.