Skip to content

Commit

Permalink
chore: add isPaused for dash playlist loader to mitigate duplicate pl…
Browse files Browse the repository at this point in the history
…aylist trigger for the main segment loader
  • Loading branch information
Dzianis Dashkevich committed Nov 5, 2024
1 parent 626123f commit 0a44def
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export default class DashPlaylistLoader extends EventTarget {
constructor(srcUrlOrPlaylist, vhs, options = { }, mainPlaylistLoader) {
super();

this.isPaused_ = true;

this.mainPlaylistLoader_ = mainPlaylistLoader || this;
if (!mainPlaylistLoader) {
this.isMain_ = true;
Expand Down Expand Up @@ -345,6 +347,10 @@ export default class DashPlaylistLoader extends EventTarget {
}
}

get isPaused() {
return this.isPaused_;
}

requestErrored_(err, request, startingState) {
// disposed
if (!this.request) {
Expand Down Expand Up @@ -466,6 +472,7 @@ export default class DashPlaylistLoader extends EventTarget {
}

dispose() {
this.isPaused_ = true;
this.trigger('dispose');
this.stopRequest();
this.loadedPlaylists_ = {};
Expand Down Expand Up @@ -571,6 +578,8 @@ export default class DashPlaylistLoader extends EventTarget {
}

pause() {
this.isPaused_ = true;

if (this.mainPlaylistLoader_.createMupOnMedia_) {
this.off('loadedmetadata', this.mainPlaylistLoader_.createMupOnMedia_);
this.mainPlaylistLoader_.createMupOnMedia_ = null;
Expand All @@ -590,6 +599,8 @@ export default class DashPlaylistLoader extends EventTarget {
}

load(isFinalRendition) {
this.isPaused_ = false;

window.clearTimeout(this.mediaUpdateTimeout);
this.mediaUpdateTimeout = null;

Expand Down
11 changes: 10 additions & 1 deletion src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,16 @@ export class PlaylistController extends videojs.EventTarget {

if (this.sourceType_ === 'dash') {
// we don't want to re-request the same hls playlist right after it was changed
this.mainPlaylistLoader_.load();

// Initially it was implemented as workaround to restart playlist loader for live
// when playlist loader is paused because of playlist exclusions:
// see: https://github.com/videojs/http-streaming/pull/1339
// but this introduces duplicate "loadedplaylist" event.
// Ideally we want to re-think playlist loader life-cycle events,
// but simply checking "paused" state should help a lot
if (this.mainPlaylistLoader_.isPaused) {
this.mainPlaylistLoader_.load();
}
}

// TODO: Create a new event on the PlaylistLoader that signals
Expand Down

0 comments on commit 0a44def

Please sign in to comment.