From 2554270e0107e56182931747312abb745f24626f Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Fri, 13 Dec 2024 16:25:55 -0800 Subject: [PATCH 1/2] Fix additional asset player creation between assets at start Fix uncaught play() Promise --- src/controller/interstitials-controller.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controller/interstitials-controller.ts b/src/controller/interstitials-controller.ts index c1679eccd8c..32fc16b809f 100644 --- a/src/controller/interstitials-controller.ts +++ b/src/controller/interstitials-controller.ts @@ -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 @@ -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; @@ -1644,7 +1646,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`, } else if ( bufferIsEmpty && playingItem && - bufferingItem !== playingItem && + !this.itemsMatch(playingItem, bufferingItem) && bufferEndIndex === playingIndex ) { this.bufferedToItem(playingItem); From ce8aa05a1a9c138354ca5df69e445798af27641f Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Fri, 13 Dec 2024 17:28:07 -0800 Subject: [PATCH 2/2] Update interstitial controller item references when the schedule is updated --- src/controller/interstitials-controller.ts | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/controller/interstitials-controller.ts b/src/controller/interstitials-controller.ts index 32fc16b809f..83f52f19d9e 100644 --- a/src/controller/interstitials-controller.ts +++ b/src/controller/interstitials-controller.ts @@ -1476,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); @@ -1658,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 @@ -1694,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; }