Skip to content

Commit

Permalink
Destroy hls instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
i-zolotarenko committed Dec 12, 2023
1 parent fd9c638 commit 810a228
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions p2p-media-loader-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ function App() {
const createNewPlayer = () => {
setHttpLoadedGlob(0);
setP2PLoadedGlob(0);

(window as unknown as ExtendedWindow).videoPlayer?.destroy?.();
hlsInstance.current?.destroy();
void shakaInstance.current?.destroy();
switch (playerType) {
case "hls-dplayer":
initHlsDPlayer(streamUrl);
Expand Down
7 changes: 2 additions & 5 deletions packages/p2p-media-loader-hlsjs/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export class Engine {

initHLSEvents(hls: Hls) {
if (this._hlsInstance === hls) return;

if (this._hlsInstance) {
this.updateHlsEventsHandlers("unregister");
this.updateMediaElementEventHandlers("unregister");
}
if (this._hlsInstance) this.destroy();
this._hlsInstance = hls;
this.updateHlsEventsHandlers("register");
this.updateMediaElementEventHandlers("unregister");
Expand Down Expand Up @@ -157,6 +153,7 @@ export class Engine {
return class PlaylistLoader extends PlaylistLoaderBase {
constructor(config: HlsConfig) {
super(config);
if (engine._hlsInstance) return;
const hlsInstance = engine.hlsInstanceGetter?.();
if (hlsInstance) engine.initHLSEvents(hlsInstance);
}
Expand Down

0 comments on commit 810a228

Please sign in to comment.