Skip to content
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

Interstitials: Fix additional asset player creation between assets at start #6914

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 26 additions & 17 deletions src/controller/interstitials-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export type PlayheadTimes = {
};

function playWithCatch(media: HTMLMediaElement | null) {
media?.play().catch(/* no-op */);
media?.play().catch(() => {
/* no-op */
});
}

export default class InterstitialsController
Expand Down Expand Up @@ -1383,7 +1385,7 @@ MediaSource ${JSON.stringify(attachMediaSourceData)} from ${logFromSource}`,
const { playingItem } = this;
if (
playingItem &&
playingItem !== this.bufferingItem &&
!this.itemsMatch(playingItem, this.bufferingItem) &&
!this.isInterstitial(playingItem)
) {
const timelinePos = this.timelinePos;
Expand Down Expand Up @@ -1474,16 +1476,23 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
});

// Update schedule item references
// Do not change Interstitial playingItem - used for INTERSTITIAL_ASSET_ENDED and INTERSTITIAL_ENDED
if (playingItem && !playingItem.event) {
this.playingItem = this.updateItem(playingItem, this.timelinePos);
// Do not replace Interstitial playingItem without a match - used for INTERSTITIAL_ASSET_ENDED and INTERSTITIAL_ENDED
if (playingItem) {
const updatedPlayingItem = this.updateItem(playingItem, this.timelinePos);
if (this.itemsMatch(playingItem, updatedPlayingItem)) {
this.playingItem = updatedPlayingItem;
}
}
// Do not change Interstitial bufferingItem - used for transfering media element or source
// Do not replace Interstitial bufferingItem without a match - used for transfering media element or source
const bufferingItem = this.bufferingItem;
if (bufferingItem) {
if (!bufferingItem.event) {
this.bufferingItem = this.updateItem(bufferingItem, this.bufferedPos);
} else if (!this.updateItem(bufferingItem)) {
const updatedBufferingItem = this.updateItem(
bufferingItem,
this.bufferedPos,
);
if (this.itemsMatch(bufferingItem, updatedBufferingItem)) {
this.bufferingItem = updatedBufferingItem;
} else if (bufferingItem.event) {
// Interstitial removed from schedule (Live -> VOD or other scenario where Start Date is outside the range of VOD Playlist)
this.bufferingItem = null;
this.clearInterstitial(bufferingItem.event, null);
Expand Down Expand Up @@ -1644,7 +1653,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
} else if (
bufferIsEmpty &&
playingItem &&
bufferingItem !== playingItem &&
!this.itemsMatch(playingItem, bufferingItem) &&
bufferEndIndex === playingIndex
) {
this.bufferedToItem(playingItem);
Expand All @@ -1656,14 +1665,12 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
): InterstitialScheduleItem | null {
const bufferingLast = this.bufferingItem;
const schedule = this.schedule;
const { items, events } = schedule;

if (
items &&
events &&
(!bufferingLast ||
schedule.findItemIndex(bufferingLast) !== schedule.findItemIndex(item))
) {
if (!this.itemsMatch(item, bufferingLast)) {
const { items, events } = schedule;
if (!items || !events) {
return bufferingLast;
}
const isInterstitial = this.isInterstitial(item);
const bufferingPlayer = this.getBufferingPlayer();
const timeRemaining = bufferingPlayer
Expand Down Expand Up @@ -1692,6 +1699,8 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
bufferingIndex: this.findItemIndex(item),
playingIndex: this.findItemIndex(this.playingItem),
});
} else if (this.bufferingItem !== item) {
this.bufferingItem = item;
}
return bufferingLast;
}
Expand Down
Loading