Skip to content

Commit

Permalink
Retry audio and subtitle playlist loading after failure on level swit…
Browse files Browse the repository at this point in the history
…ch when no alternate is available
  • Loading branch information
robwalch committed Feb 25, 2023
1 parent c228d11 commit fa704b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ class AudioTrackController extends BasePlaylistController {
this.hls.trigger(Events.AUDIO_TRACKS_UPDATED, audioTracksUpdated);

this.selectInitialTrack();
} else if (
this.timer === -1 &&
this.requestScheduled === -1 &&
!this.currentTrack?.details
) {
} else if (this.shouldReloadPlaylist(this.currentTrack)) {
// Retry playlist loading if no playlist is or has been loaded yet
this.setAudioTrack(this.trackId);
}
Expand Down
16 changes: 14 additions & 2 deletions src/controller/base-playlist-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,27 @@ export default class BasePlaylistController implements NetworkComponentAPI {
// Loading is handled by the subclasses
}

protected shouldLoadPlaylist(playlist: Level | MediaPlaylist): boolean {
protected shouldLoadPlaylist(
playlist: Level | MediaPlaylist | null | undefined
): boolean {
return (
this.canLoad &&
playlist &&
!!playlist &&
!!playlist.url &&
(!playlist.details || playlist.details.live)
);
}

protected shouldReloadPlaylist(
playlist: Level | MediaPlaylist | null | undefined
): boolean {
return (
this.timer === -1 &&
this.requestScheduled === -1 &&
this.shouldLoadPlaylist(playlist)
);
}

protected playlistLoaded(
index: number,
data: LevelLoadedData | AudioTrackLoadedData | TrackLoadedData,
Expand Down
6 changes: 1 addition & 5 deletions src/controller/subtitle-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,7 @@ class SubtitleTrackController extends BasePlaylistController {
if (initialTrackId !== -1) {
this.setSubtitleTrack(initialTrackId, lastTrack);
}
} else if (
this.timer === -1 &&
this.requestScheduled === -1 &&
!lastTrack?.details
) {
} else if (this.shouldReloadPlaylist(lastTrack)) {
// Retry playlist loading if no playlist is or has been loaded yet
this.setSubtitleTrack(this.trackId, lastTrack);
}
Expand Down

0 comments on commit fa704b5

Please sign in to comment.