stormcloud-video-player 0.3.4 → 0.3.6

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.
@@ -3191,21 +3191,38 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3191
3191
  this.adPodQueue = [...vastTagUrls];
3192
3192
  if (this.isAdaptiveMode) {
3193
3193
  if (this.config.debugAdTiming) {
3194
- console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3194
+ console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
3195
3195
  }
3196
3196
  try {
3197
- await this.preloadAllAdsInBackground();
3197
+ const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
3198
+ for (let i = 0; i < adsToPreloadBeforeStart; i++) {
3199
+ const url = this.adPodAllUrls[i];
3200
+ if (url) {
3201
+ await this.preloadSingleAd(url);
3202
+ if (this.config.debugAdTiming) {
3203
+ console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
3204
+ }
3205
+ }
3206
+ }
3198
3207
  if (this.config.debugAdTiming) {
3199
- console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3208
+ console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
3200
3209
  }
3201
3210
  } catch (error) {
3202
3211
  if (this.config.debugAdTiming) {
3203
3212
  console.warn(
3204
- "[ADAPTIVE-POD] Error in preloading:",
3213
+ "[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
3205
3214
  error
3206
3215
  );
3207
3216
  }
3208
3217
  }
3218
+ this.preloadAllAdsInBackground().catch((error) => {
3219
+ if (this.config.debugAdTiming) {
3220
+ console.warn(
3221
+ "[ADAPTIVE-POD] Error in background preloading:",
3222
+ error
3223
+ );
3224
+ }
3225
+ });
3209
3226
  await this.playAdPod();
3210
3227
  } else {
3211
3228
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3230,7 +3247,7 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3230
3247
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3231
3248
  return;
3232
3249
  }
3233
- const waitTime = this.isAdaptiveMode ? 100 : 500;
3250
+ const waitTime = this.isAdaptiveMode ? 50 : 500;
3234
3251
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3235
3252
  if (this.config.debugAdTiming) {
3236
3253
  console.log(
@@ -3712,21 +3729,24 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3712
3729
  for (const duration of this.fetchedAdDurations.values()) {
3713
3730
  totalFetchedDurationMs += duration * 1e3;
3714
3731
  }
3715
- const remainingTimeMs = this.targetAdBreakDurationMs - totalFetchedDurationMs;
3732
+ const fetchedCount = this.fetchedAdDurations.size;
3733
+ const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3734
+ const queuedButNotFetched = this.adPodAllUrls.length - fetchedCount;
3735
+ const estimatedQueuedDurationMs = queuedButNotFetched * averageDurationMs;
3736
+ const estimatedTotalDurationMs = totalFetchedDurationMs + estimatedQueuedDurationMs;
3737
+ const remainingTimeMs = this.targetAdBreakDurationMs - estimatedTotalDurationMs;
3716
3738
  if (remainingTimeMs <= 0) {
3717
3739
  if (this.config.debugAdTiming) {
3718
3740
  console.log(
3719
- `[ADAPTIVE-POD] \u2705 Target duration reached: ${totalFetchedDurationMs}ms / ${this.targetAdBreakDurationMs}ms`
3741
+ `[ADAPTIVE-POD] \u2705 Target duration met: Fetched=${totalFetchedDurationMs}ms + Queued(${queuedButNotFetched} ads)=${estimatedQueuedDurationMs}ms = ${estimatedTotalDurationMs}ms / Target=${this.targetAdBreakDurationMs}ms`
3720
3742
  );
3721
3743
  }
3722
3744
  return 0;
3723
3745
  }
3724
- const fetchedCount = this.fetchedAdDurations.size;
3725
- const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3726
3746
  const additionalAds = Math.ceil(remainingTimeMs / averageDurationMs);
3727
3747
  if (this.config.debugAdTiming) {
3728
3748
  console.log(
3729
- `[ADAPTIVE-POD] \u{1F4CA} Need ${additionalAds} more ads | Fetched: ${totalFetchedDurationMs}ms / Target: ${this.targetAdBreakDurationMs}ms | Remaining: ${remainingTimeMs}ms | Avg duration: ${averageDurationMs}ms`
3749
+ `[ADAPTIVE-POD] \u{1F4CA} Need ${additionalAds} more ads | Fetched: ${totalFetchedDurationMs}ms (${fetchedCount} ads) | Queued: ${estimatedQueuedDurationMs}ms (${queuedButNotFetched} ads) | Target: ${this.targetAdBreakDurationMs}ms | Remaining: ${remainingTimeMs}ms | Avg duration: ${averageDurationMs}ms`
3730
3750
  );
3731
3751
  }
3732
3752
  return additionalAds;
@@ -3793,16 +3813,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3793
3813
  }
3794
3814
  }
3795
3815
  async preloadAllAdsInBackground() {
3816
+ var _a, _b;
3796
3817
  if (this.adPodAllUrls.length === 0) {
3797
3818
  return;
3798
3819
  }
3799
3820
  if (this.isAdaptiveMode) {
3800
3821
  if (this.config.debugAdTiming) {
3801
3822
  console.log(
3802
- `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3823
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of remaining ads`
3803
3824
  );
3804
3825
  }
3805
3826
  const processedUrls = /* @__PURE__ */ new Set();
3827
+ for (const url of this.adPodAllUrls) {
3828
+ if (((_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, url)) || this.fetchedAdDurations.has(url)) {
3829
+ processedUrls.add(url);
3830
+ }
3831
+ }
3832
+ if (this.config.debugAdTiming && processedUrls.size > 0) {
3833
+ console.log(
3834
+ `[ADAPTIVE-POD] \u{1F4E6} Skipping ${processedUrls.size} already-preloaded ads`
3835
+ );
3836
+ }
3806
3837
  while (true) {
3807
3838
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3808
3839
  if (!nextUrl) {