stormcloud-video-player 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,12 @@ declare class StormcloudVideoPlayer {
41
41
  private targetAdBreakDurationMs;
42
42
  private isAdaptiveMode;
43
43
  private failedVastUrls;
44
+ private continuousFetchingActive;
45
+ private adRequestQueue;
46
+ private successfulAdRequests;
47
+ private maxPlaceholderDurationMs;
48
+ private placeholderStartTimeMs;
49
+ private isShowingPlaceholder;
44
50
  constructor(config: StormcloudVideoPlayerConfig);
45
51
  private createAdPlayer;
46
52
  load(): Promise<void>;
@@ -68,7 +74,11 @@ declare class StormcloudVideoPlayer {
68
74
  shouldShowNativeControls(): boolean;
69
75
  private shouldContinueLiveStreamDuringAds;
70
76
  private handleAdStart;
71
- private playAdPod;
77
+ private startContinuousFetching;
78
+ private continuousFetchLoop;
79
+ private stopContinuousFetching;
80
+ private tryNextAvailableAd;
81
+ private showPlaceholderAndWaitForAds;
72
82
  private findCurrentOrNextBreak;
73
83
  private onTimeUpdate;
74
84
  private handleMidAdJoin;
@@ -81,7 +91,6 @@ declare class StormcloudVideoPlayer {
81
91
  private playSingleAd;
82
92
  private handleAdPodComplete;
83
93
  private handleAdFailure;
84
- private tryNextAdWithRetry;
85
94
  private startAdRequestWatchdog;
86
95
  private clearAdRequestWatchdog;
87
96
  private startAdFailsafeTimer;
@@ -2085,6 +2085,12 @@ var StormcloudVideoPlayer = class {
2085
2085
  this.targetAdBreakDurationMs = null;
2086
2086
  this.isAdaptiveMode = false;
2087
2087
  this.failedVastUrls = /* @__PURE__ */ new Set();
2088
+ this.continuousFetchingActive = false;
2089
+ this.adRequestQueue = [];
2090
+ this.successfulAdRequests = [];
2091
+ this.maxPlaceholderDurationMs = 5e3;
2092
+ this.placeholderStartTimeMs = null;
2093
+ this.isShowingPlaceholder = false;
2088
2094
  initializePolyfills();
2089
2095
  const browserOverrides = getBrowserConfigOverrides();
2090
2096
  this.config = { ...config, ...browserOverrides };
@@ -2391,16 +2397,11 @@ var StormcloudVideoPlayer = class {
2391
2397
  return;
2392
2398
  }
2393
2399
  const remaining = this.getRemainingAdMs();
2394
- if (remaining > 500 && this.adPodQueue.length > 0) {
2395
- const nextPreloaded = this.findNextPreloadedAd();
2396
- if (nextPreloaded) {
2397
- this.currentAdIndex++;
2398
- this.playSingleAd(nextPreloaded).catch(() => {
2399
- this.handleAdPodComplete();
2400
- });
2401
- } else {
2402
- this.handleAdPodComplete();
2403
- }
2400
+ if (this.config.debugAdTiming) {
2401
+ console.log(`[CONTINUOUS-FETCH] content_resume event: remaining=${remaining}ms, queued ads=${this.adRequestQueue.length}`);
2402
+ }
2403
+ if (remaining > 500) {
2404
+ this.tryNextAvailableAd();
2404
2405
  } else {
2405
2406
  this.handleAdPodComplete();
2406
2407
  }
@@ -3000,155 +3001,240 @@ var StormcloudVideoPlayer = class {
3000
3001
  return true;
3001
3002
  }
3002
3003
  async handleAdStart(_marker) {
3003
- var _a;
3004
3004
  const scheduled = this.findCurrentOrNextBreak(
3005
3005
  this.video.currentTime * 1e3
3006
3006
  );
3007
3007
  const tags = this.selectVastTagsForBreak(scheduled);
3008
- let vastTagUrls = [];
3008
+ let baseVastUrl;
3009
3009
  if (this.apiVastTagUrl) {
3010
- let numberOfAds = 1;
3011
- if (this.isLiveStream) {
3012
- const adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled == null ? void 0 : scheduled.durationMs;
3013
- if (adBreakDurationMs != null && adBreakDurationMs > 0) {
3014
- this.isAdaptiveMode = true;
3015
- this.targetAdBreakDurationMs = adBreakDurationMs;
3016
- this.fetchedAdDurations.clear();
3017
- numberOfAds = 2;
3018
- if (this.config.debugAdTiming) {
3019
- console.log(
3020
- `[ADAPTIVE-POD] \u{1F4FA} LIVE MODE (ADAPTIVE): Target duration=${adBreakDurationMs}ms | Starting with ${numberOfAds} ads, will fetch actual durations and add more dynamically`
3021
- );
3022
- }
3023
- } else {
3024
- if (this.config.debugAdTiming) {
3025
- console.warn(
3026
- "[DEBUG-POD] \u26A0\uFE0F LIVE MODE: No duration available, defaulting to 1 ad"
3027
- );
3028
- }
3010
+ baseVastUrl = this.apiVastTagUrl;
3011
+ } else if (tags && tags.length > 0 && tags[0]) {
3012
+ baseVastUrl = tags[0];
3013
+ } else {
3014
+ return;
3015
+ }
3016
+ const adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled == null ? void 0 : scheduled.durationMs;
3017
+ if (this.isLiveStream && adBreakDurationMs != null && adBreakDurationMs > 0) {
3018
+ this.isAdaptiveMode = true;
3019
+ this.targetAdBreakDurationMs = adBreakDurationMs;
3020
+ this.fetchedAdDurations.clear();
3021
+ if (this.config.debugAdTiming) {
3022
+ console.log(
3023
+ `[CONTINUOUS-FETCH] \u{1F4FA} LIVE MODE: Target duration=${adBreakDurationMs}ms | Will continuously fetch ads during break`
3024
+ );
3025
+ }
3026
+ } else {
3027
+ this.isAdaptiveMode = false;
3028
+ this.targetAdBreakDurationMs = null;
3029
+ this.fetchedAdDurations.clear();
3030
+ if (this.config.debugAdTiming) {
3031
+ console.log(
3032
+ `[CONTINUOUS-FETCH] \u{1F3AC} VOD MODE: Using fixed ad strategy`
3033
+ );
3034
+ }
3035
+ }
3036
+ this.adPodAllUrls = [];
3037
+ this.preloadingAdUrls.clear();
3038
+ this.vastToMediaUrlMap.clear();
3039
+ this.preloadedMediaUrls.clear();
3040
+ this.preloadingMediaUrls.clear();
3041
+ this.failedVastUrls.clear();
3042
+ this.adRequestQueue = [];
3043
+ this.successfulAdRequests = [];
3044
+ this.continuousFetchingActive = true;
3045
+ this.isShowingPlaceholder = false;
3046
+ this.placeholderStartTimeMs = null;
3047
+ const currentMuted = this.video.muted;
3048
+ const currentVolume = this.video.volume;
3049
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3050
+ this.inAdBreak = true;
3051
+ this.currentAdIndex = 0;
3052
+ this.totalAdsInBreak = 1;
3053
+ this.adPodQueue = [];
3054
+ if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
3055
+ this.expectedAdBreakDurationMs = adBreakDurationMs;
3056
+ this.currentAdBreakStartWallClockMs = Date.now();
3057
+ this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
3058
+ }
3059
+ if (this.config.debugAdTiming) {
3060
+ console.log("[CONTINUOUS-FETCH] \u{1F680} Immediately requesting first ad...");
3061
+ }
3062
+ const firstAdUrlArray = this.generateVastUrlsWithCorrelators(baseVastUrl, 1);
3063
+ const firstAdUrl = firstAdUrlArray[0];
3064
+ if (!firstAdUrl) {
3065
+ if (this.config.debugAdTiming) {
3066
+ console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F Failed to generate first ad URL");
3067
+ }
3068
+ this.handleAdPodComplete();
3069
+ return;
3070
+ }
3071
+ try {
3072
+ await this.ima.requestAds(firstAdUrl);
3073
+ if (this.config.debugAdTiming) {
3074
+ console.log("[CONTINUOUS-FETCH] \u2705 First ad request successful, starting playback");
3075
+ }
3076
+ this.successfulAdRequests.push(firstAdUrl);
3077
+ this.currentAdIndex++;
3078
+ this.startContinuousFetching(baseVastUrl);
3079
+ await this.ima.play();
3080
+ } catch (error) {
3081
+ if (this.config.debugAdTiming) {
3082
+ console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
3083
+ }
3084
+ this.failedVastUrls.add(firstAdUrl);
3085
+ this.startContinuousFetching(baseVastUrl);
3086
+ this.tryNextAvailableAd();
3087
+ }
3088
+ }
3089
+ startContinuousFetching(baseVastUrl) {
3090
+ if (!this.continuousFetchingActive) {
3091
+ return;
3092
+ }
3093
+ if (this.config.debugAdTiming) {
3094
+ console.log("[CONTINUOUS-FETCH] \u{1F504} Starting continuous ad fetching loop");
3095
+ }
3096
+ this.continuousFetchLoop(baseVastUrl);
3097
+ }
3098
+ async continuousFetchLoop(baseVastUrl) {
3099
+ while (this.continuousFetchingActive && this.inAdBreak) {
3100
+ const remaining = this.getRemainingAdMs();
3101
+ if (remaining <= 0) {
3102
+ if (this.config.debugAdTiming) {
3103
+ console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F Ad break time expired, stopping fetch loop");
3029
3104
  }
3030
- } else {
3031
- this.isAdaptiveMode = false;
3032
- this.targetAdBreakDurationMs = null;
3033
- this.fetchedAdDurations.clear();
3034
- if (this.apiNumberAds && this.apiNumberAds > 1) {
3035
- numberOfAds = this.apiNumberAds;
3105
+ break;
3106
+ }
3107
+ if (this.adRequestQueue.length > 0) {
3108
+ if (this.config.debugAdTiming) {
3109
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Already have ${this.adRequestQueue.length} ads queued, waiting...`);
3110
+ }
3111
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
3112
+ continue;
3113
+ }
3114
+ const newAdUrl = this.generateVastUrlsWithCorrelators(baseVastUrl, 1)[0];
3115
+ if (!newAdUrl || this.failedVastUrls.has(newAdUrl)) {
3116
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
3117
+ continue;
3118
+ }
3119
+ if (this.config.debugAdTiming) {
3120
+ console.log("[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch additional ad...");
3121
+ }
3122
+ try {
3123
+ const response = await fetch(newAdUrl, { mode: "cors" });
3124
+ if (!response.ok) {
3125
+ throw new Error(`Failed to fetch VAST: ${response.status}`);
3126
+ }
3127
+ const xmlText = await response.text();
3128
+ const parser = new DOMParser();
3129
+ const xmlDoc = parser.parseFromString(xmlText, "text/xml");
3130
+ const mediaFiles = xmlDoc.querySelectorAll("MediaFile");
3131
+ if (mediaFiles.length === 0) {
3036
3132
  if (this.config.debugAdTiming) {
3037
- console.log(
3038
- `[DEBUG-POD] \u{1F3AC} VOD MODE (FIXED): Using number_ads=${numberOfAds} from API`
3039
- );
3133
+ console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
3040
3134
  }
3135
+ this.failedVastUrls.add(newAdUrl);
3136
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
3137
+ continue;
3041
3138
  }
3042
- }
3043
- if (numberOfAds > 1) {
3044
- vastTagUrls = this.generateVastUrlsWithCorrelators(
3045
- this.apiVastTagUrl,
3046
- numberOfAds
3047
- );
3048
3139
  if (this.config.debugAdTiming) {
3049
- console.log(
3050
- `[DEBUG-POD] \u{1F504} Generated ${vastTagUrls.length} initial VAST URLs with unique correlators`
3051
- );
3140
+ console.log("[CONTINUOUS-FETCH] \u2705 Successfully fetched new ad, adding to queue");
3052
3141
  }
3053
- } else {
3054
- vastTagUrls = [this.apiVastTagUrl];
3142
+ this.adRequestQueue.push(newAdUrl);
3143
+ this.totalAdsInBreak++;
3144
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
3145
+ } catch (error) {
3146
+ if (this.config.debugAdTiming) {
3147
+ console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3148
+ }
3149
+ this.failedVastUrls.add(newAdUrl);
3150
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
3055
3151
  }
3056
- } else if (tags && tags.length > 0) {
3057
- vastTagUrls = tags;
3058
- } else {
3152
+ }
3153
+ if (this.config.debugAdTiming) {
3154
+ console.log("[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended");
3155
+ }
3156
+ }
3157
+ stopContinuousFetching() {
3158
+ this.continuousFetchingActive = false;
3159
+ if (this.config.debugAdTiming) {
3160
+ console.log("[CONTINUOUS-FETCH] \u{1F6D1} Stopping continuous ad fetching");
3161
+ }
3162
+ }
3163
+ async tryNextAvailableAd() {
3164
+ const remaining = this.getRemainingAdMs();
3165
+ if (remaining <= 500) {
3166
+ if (this.config.debugAdTiming) {
3167
+ console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No time remaining, ending ad break");
3168
+ }
3169
+ this.handleAdPodComplete();
3059
3170
  return;
3060
3171
  }
3061
- if (vastTagUrls.length > 0) {
3062
- this.adPodAllUrls = [...vastTagUrls];
3063
- this.preloadingAdUrls.clear();
3064
- this.vastToMediaUrlMap.clear();
3065
- this.preloadedMediaUrls.clear();
3066
- this.preloadingMediaUrls.clear();
3067
- this.failedVastUrls.clear();
3068
- const currentMuted = this.video.muted;
3069
- const currentVolume = this.video.volume;
3070
- this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3071
- this.inAdBreak = true;
3072
- this.currentAdIndex = 0;
3073
- this.totalAdsInBreak = vastTagUrls.length;
3074
- this.adPodQueue = [...vastTagUrls];
3075
- if (this.isAdaptiveMode) {
3172
+ if (this.adRequestQueue.length > 0) {
3173
+ const nextAdUrl = this.adRequestQueue.shift();
3174
+ if (nextAdUrl) {
3076
3175
  if (this.config.debugAdTiming) {
3077
- console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
3078
- }
3079
- try {
3080
- const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
3081
- for (let i = 0; i < adsToPreloadBeforeStart; i++) {
3082
- const url = this.adPodAllUrls[i];
3083
- if (url) {
3084
- await this.preloadSingleAd(url);
3085
- if (this.config.debugAdTiming) {
3086
- console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
3087
- }
3088
- }
3089
- }
3090
- if (this.config.debugAdTiming) {
3091
- console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
3092
- }
3093
- } catch (error) {
3094
- if (this.config.debugAdTiming) {
3095
- console.warn(
3096
- "[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
3097
- error
3098
- );
3099
- }
3176
+ console.log("[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad");
3100
3177
  }
3101
- this.preloadAllAdsInBackground().catch((error) => {
3102
- if (this.config.debugAdTiming) {
3103
- console.warn(
3104
- "[ADAPTIVE-POD] Error in background preloading:",
3105
- error
3106
- );
3107
- }
3108
- });
3109
- await this.playAdPod();
3110
- } else {
3111
- this.preloadAllAdsInBackground().catch((error) => {
3112
- if (this.config.debugAdTiming) {
3113
- console.warn(
3114
- "[StormcloudVideoPlayer] Error in background preloading:",
3115
- error
3116
- );
3117
- }
3178
+ this.currentAdIndex++;
3179
+ await this.playSingleAd(nextAdUrl).catch(() => {
3180
+ this.tryNextAvailableAd();
3118
3181
  });
3119
- await this.playAdPod();
3182
+ return;
3120
3183
  }
3121
3184
  }
3122
- if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
3123
- this.expectedAdBreakDurationMs = scheduled.durationMs;
3124
- this.currentAdBreakStartWallClockMs = (_a = this.currentAdBreakStartWallClockMs) != null ? _a : Date.now();
3125
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
3185
+ if (!this.isShowingPlaceholder && remaining > 1e3) {
3186
+ this.showPlaceholderAndWaitForAds();
3187
+ } else {
3188
+ if (this.config.debugAdTiming) {
3189
+ console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available, ending ad break");
3190
+ }
3191
+ this.handleAdPodComplete();
3126
3192
  }
3127
3193
  }
3128
- async playAdPod() {
3129
- if (this.adPodQueue.length === 0) {
3194
+ async showPlaceholderAndWaitForAds() {
3195
+ const remaining = this.getRemainingAdMs();
3196
+ const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
3197
+ if (waitTime < 1e3) {
3198
+ this.handleAdPodComplete();
3130
3199
  return;
3131
3200
  }
3132
- const waitTime = this.isAdaptiveMode ? 50 : 500;
3133
- await new Promise((resolve) => setTimeout(resolve, waitTime));
3134
- const firstPreloaded = this.findNextPreloadedAd();
3135
- if (!firstPreloaded) {
3136
- const firstAd = this.adPodQueue.shift();
3137
- if (firstAd) {
3138
- this.currentAdIndex++;
3139
- try {
3140
- await this.playSingleAd(firstAd);
3141
- } catch (error) {
3142
- return;
3201
+ if (this.config.debugAdTiming) {
3202
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
3203
+ }
3204
+ this.isShowingPlaceholder = true;
3205
+ this.placeholderStartTimeMs = Date.now();
3206
+ this.ima.showPlaceholder();
3207
+ const checkInterval = 500;
3208
+ const maxChecks = Math.floor(waitTime / checkInterval);
3209
+ for (let i = 0; i < maxChecks; i++) {
3210
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
3211
+ if (!this.inAdBreak) {
3212
+ return;
3213
+ }
3214
+ if (this.adRequestQueue.length > 0) {
3215
+ if (this.config.debugAdTiming) {
3216
+ console.log("[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder");
3217
+ }
3218
+ this.isShowingPlaceholder = false;
3219
+ this.placeholderStartTimeMs = null;
3220
+ this.ima.hidePlaceholder();
3221
+ const nextAdUrl = this.adRequestQueue.shift();
3222
+ if (nextAdUrl) {
3223
+ this.currentAdIndex++;
3224
+ await this.playSingleAd(nextAdUrl).catch(() => {
3225
+ this.tryNextAvailableAd();
3226
+ });
3143
3227
  }
3228
+ return;
3144
3229
  }
3145
- return;
3146
3230
  }
3147
- this.currentAdIndex++;
3148
- try {
3149
- await this.playSingleAd(firstPreloaded);
3150
- } catch (error) {
3231
+ if (this.config.debugAdTiming) {
3232
+ console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached, no ads fetched");
3151
3233
  }
3234
+ this.isShowingPlaceholder = false;
3235
+ this.placeholderStartTimeMs = null;
3236
+ this.ima.hidePlaceholder();
3237
+ this.handleAdPodComplete();
3152
3238
  }
3153
3239
  findCurrentOrNextBreak(nowMs) {
3154
3240
  var _a;
@@ -3308,10 +3394,18 @@ var StormcloudVideoPlayer = class {
3308
3394
  this.clearAdRequestWatchdog();
3309
3395
  this.clearAdFailsafeTimer();
3310
3396
  this.activeAdRequestToken = null;
3397
+ this.stopContinuousFetching();
3398
+ if (this.isShowingPlaceholder) {
3399
+ this.ima.hidePlaceholder();
3400
+ this.isShowingPlaceholder = false;
3401
+ this.placeholderStartTimeMs = null;
3402
+ }
3311
3403
  this.preloadingAdUrls.clear();
3312
3404
  this.vastToMediaUrlMap.clear();
3313
3405
  this.preloadedMediaUrls.clear();
3314
3406
  this.preloadingMediaUrls.clear();
3407
+ this.adRequestQueue = [];
3408
+ this.successfulAdRequests = [];
3315
3409
  this.inAdBreak = false;
3316
3410
  this.expectedAdBreakDurationMs = void 0;
3317
3411
  this.currentAdBreakStartWallClockMs = void 0;
@@ -3338,61 +3432,14 @@ var StormcloudVideoPlayer = class {
3338
3432
  }
3339
3433
  }
3340
3434
  handleAdFailure() {
3341
- const remaining = this.getRemainingAdMs();
3342
- const availableAds = this.adPodQueue.filter((url) => !this.failedVastUrls.has(url)).length;
3343
- if (remaining > 500 && availableAds > 0) {
3344
- if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
3345
- console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
3346
- setTimeout(() => {
3347
- this.tryNextAdWithRetry(0);
3348
- }, 1500);
3349
- return;
3350
- }
3351
- const nextPreloaded = this.findNextPreloadedAd();
3352
- if (nextPreloaded) {
3353
- this.currentAdIndex++;
3354
- this.playSingleAd(nextPreloaded).catch(() => {
3355
- this.handleAdPodComplete();
3356
- });
3357
- return;
3358
- }
3359
- }
3360
- console.error("[AD-ERROR] All ads failed or time expired. Failed URLs:", this.failedVastUrls.size);
3361
- this.handleAdPodComplete();
3362
- }
3363
- tryNextAdWithRetry(retryCount) {
3364
- const maxRetries = 3;
3365
3435
  const remaining = this.getRemainingAdMs();
3366
3436
  if (this.config.debugAdTiming) {
3367
- console.log(
3368
- `[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
3369
- );
3370
- }
3371
- if (remaining <= 500 || this.adPodQueue.length === 0) {
3372
- console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
3373
- this.handleAdPodComplete();
3374
- return;
3437
+ console.log(`[CONTINUOUS-FETCH] Ad failure: remaining=${remaining}ms, queued ads=${this.adRequestQueue.length}`);
3375
3438
  }
3376
- const nextPreloaded = this.findNextPreloadedAd();
3377
- if (nextPreloaded) {
3378
- this.currentAdIndex++;
3379
- console.log(
3380
- `[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
3381
- );
3382
- this.playSingleAd(nextPreloaded).catch(() => {
3383
- this.handleAdPodComplete();
3384
- });
3385
- } else if (retryCount < maxRetries) {
3386
- console.log(
3387
- `[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
3388
- );
3389
- setTimeout(() => {
3390
- this.tryNextAdWithRetry(retryCount + 1);
3391
- }, 1e3);
3439
+ if (remaining > 500) {
3440
+ this.tryNextAvailableAd();
3392
3441
  } else {
3393
- console.log(
3394
- `[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
3395
- );
3442
+ console.error("[AD-ERROR] Ad failed and no time remaining. Failed URLs:", this.failedVastUrls.size);
3396
3443
  this.handleAdPodComplete();
3397
3444
  }
3398
3445
  }
@@ -3990,6 +4037,7 @@ var StormcloudVideoPlayer = class {
3990
4037
  }
3991
4038
  destroy() {
3992
4039
  var _a, _b;
4040
+ this.stopContinuousFetching();
3993
4041
  this.clearAdStartTimer();
3994
4042
  this.clearAdStopTimer();
3995
4043
  this.clearAdFailsafeTimer();
@@ -4004,6 +4052,8 @@ var StormcloudVideoPlayer = class {
4004
4052
  this.preloadedMediaUrls.clear();
4005
4053
  this.preloadingMediaUrls.clear();
4006
4054
  this.adPodAllUrls = [];
4055
+ this.adRequestQueue = [];
4056
+ this.successfulAdRequests = [];
4007
4057
  }
4008
4058
  };
4009
4059