Skip to content

Fix appending of Interstitials in place that exceed X-PLAYOUT-LIMIT #7182

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,8 @@ export default Hls;
export class HlsAssetPlayer {
constructor(HlsPlayerClass: typeof Hls, userConfig: Partial<HlsConfig>, interstitial: InterstitialEvent, assetItem: InterstitialAssetItem);
// (undocumented)
get appendInPlace(): boolean;
// (undocumented)
get assetId(): InterstitialAssetId;
// (undocumented)
readonly assetItem: InterstitialAssetItem;
Expand Down
28 changes: 22 additions & 6 deletions src/controller/interstitial-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,25 @@ export class HlsAssetPlayer {
const event = this.interstitial;
if (event.playoutLimit) {
media.addEventListener('timeupdate', this.checkPlayout);
if (this.appendInPlace) {
hls.on(Events.BUFFER_APPENDED, () => {
const bufferedEnd = this.bufferedEnd;
if (this.reachedPlayout(bufferedEnd)) {
this._bufferedEosTime = bufferedEnd;
hls.trigger(Events.BUFFERED_TO_END, undefined);
}
});
}
}
});
}

get appendInPlace(): boolean {
return this.interstitial?.appendInPlace || false;
}

bufferedInPlaceToEnd(media?: HTMLMediaElement | null) {
if (!this.interstitial.appendInPlace) {
if (!this.appendInPlace) {
return false;
}
if (this.hls?.bufferedToEnd) {
Expand All @@ -80,14 +93,17 @@ export class HlsAssetPlayer {
}

private checkPlayout = () => {
const interstitial = this.interstitial;
const playoutLimit = interstitial.playoutLimit;
const currentTime = this.currentTime;
if (this.startOffset + currentTime >= playoutLimit) {
if (this.reachedPlayout(this.currentTime)) {
this.hls.trigger(Events.PLAYOUT_LIMIT_REACHED, {});
}
};

private reachedPlayout(time: number): boolean {
const interstitial = this.interstitial;
const playoutLimit = interstitial.playoutLimit;
return this.startOffset + time >= playoutLimit;
}

get destroyed(): boolean {
return !this.hls?.userConfig;
}
Expand Down Expand Up @@ -243,6 +259,6 @@ export class HlsAssetPlayer {
}

toString(): string {
return `HlsAssetPlayer: ${eventAssetToString(this.assetItem)} ${this.hls?.sessionId} ${this.interstitial?.appendInPlace ? 'append-in-place' : ''}`;
return `HlsAssetPlayer: ${eventAssetToString(this.assetItem)} ${this.hls?.sessionId} ${this.appendInPlace ? 'append-in-place' : ''}`;
}
}
Loading