stormcloud-video-player 0.2.15 → 0.2.16

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.
@@ -1778,6 +1778,8 @@ var StormcloudVideoPlayer = class {
1778
1778
  this.totalAdsInBreak = 0;
1779
1779
  this.showAds = false;
1780
1780
  this.isLiveStream = false;
1781
+ this.nativeHlsMode = false;
1782
+ this.videoSrcProtection = null;
1781
1783
  initializePolyfills();
1782
1784
  const browserOverrides = getBrowserConfigOverrides();
1783
1785
  this.config = { ...config, ...browserOverrides };
@@ -1798,7 +1800,9 @@ var StormcloudVideoPlayer = class {
1798
1800
  }
1799
1801
  if (adPlayerType === "hls") {
1800
1802
  if (this.config.debugAdTiming) {
1801
- console.log("[StormcloudVideoPlayer] Creating HLS ad player (AdStorm mode)");
1803
+ console.log(
1804
+ "[StormcloudVideoPlayer] Creating HLS ad player (AdStorm mode)"
1805
+ );
1802
1806
  }
1803
1807
  return createHlsAdPlayer(this.video, {
1804
1808
  continueLiveStreamDuringAds,
@@ -1807,7 +1811,9 @@ var StormcloudVideoPlayer = class {
1807
1811
  });
1808
1812
  } else {
1809
1813
  if (this.config.debugAdTiming) {
1810
- console.log("[StormcloudVideoPlayer] Creating Google IMA ad player (Default mode)");
1814
+ console.log(
1815
+ "[StormcloudVideoPlayer] Creating Google IMA ad player (Default mode)"
1816
+ );
1811
1817
  }
1812
1818
  return createImaController(this.video, {
1813
1819
  continueLiveStreamDuringAds
@@ -1831,11 +1837,13 @@ var StormcloudVideoPlayer = class {
1831
1837
  }
1832
1838
  this.initializeTracking();
1833
1839
  if (this.shouldUseNativeHls()) {
1840
+ this.nativeHlsMode = true;
1841
+ this.videoSrcProtection = this.config.src;
1834
1842
  this.video.src = this.config.src;
1835
1843
  this.isLiveStream = (_a = this.config.lowLatencyMode) != null ? _a : false;
1836
1844
  if (this.config.debugAdTiming) {
1837
1845
  console.log(
1838
- "[StormcloudVideoPlayer] allowNativeHls: true - VOD mode detected:",
1846
+ "[StormcloudVideoPlayer] Using native HLS playback - VOD mode:",
1839
1847
  {
1840
1848
  isLive: this.isLiveStream,
1841
1849
  allowNativeHls: this.config.allowNativeHls,
@@ -1983,7 +1991,9 @@ var StormcloudVideoPlayer = class {
1983
1991
  this.ima.initialize();
1984
1992
  this.ima.on("all_ads_completed", () => {
1985
1993
  if (this.config.debugAdTiming) {
1986
- console.log("[StormcloudVideoPlayer] IMA all_ads_completed event received");
1994
+ console.log(
1995
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received"
1996
+ );
1987
1997
  }
1988
1998
  });
1989
1999
  this.ima.on("ad_error", () => {
@@ -2048,13 +2058,31 @@ var StormcloudVideoPlayer = class {
2048
2058
  this.video.addEventListener("timeupdate", () => {
2049
2059
  this.onTimeUpdate(this.video.currentTime);
2050
2060
  });
2061
+ this.video.addEventListener("emptied", () => {
2062
+ if (this.nativeHlsMode && this.videoSrcProtection && !this.ima.isAdPlaying()) {
2063
+ if (this.config.debugAdTiming) {
2064
+ console.log(
2065
+ "[StormcloudVideoPlayer] Video src was cleared, restoring:",
2066
+ this.videoSrcProtection
2067
+ );
2068
+ }
2069
+ const currentTime = this.video.currentTime;
2070
+ const wasPaused = this.video.paused;
2071
+ this.video.src = this.videoSrcProtection;
2072
+ this.video.currentTime = currentTime;
2073
+ if (!wasPaused) {
2074
+ this.video.play().catch(() => {
2075
+ });
2076
+ }
2077
+ }
2078
+ });
2051
2079
  }
2052
2080
  shouldUseNativeHls() {
2053
2081
  const streamType = this.getStreamType();
2054
2082
  if (streamType === "other") {
2055
2083
  return true;
2056
2084
  }
2057
- const canNative = this.video.canPlayType("application/vnd.apple.mpegURL");
2085
+ const canNative = this.video.canPlayType("application/vnd.apple.mpegurl");
2058
2086
  return !!(this.config.allowNativeHls && canNative);
2059
2087
  }
2060
2088
  onId3Tag(tag) {
@@ -2481,10 +2509,7 @@ var StormcloudVideoPlayer = class {
2481
2509
  var _a, _b, _c;
2482
2510
  const vastMode = this.config.vastMode || "default";
2483
2511
  if (this.config.debugAdTiming) {
2484
- console.log(
2485
- "[StormcloudVideoPlayer] VAST mode:",
2486
- vastMode
2487
- );
2512
+ console.log("[StormcloudVideoPlayer] VAST mode:", vastMode);
2488
2513
  }
2489
2514
  if (vastMode === "adstorm") {
2490
2515
  if (!this.config.licenseKey) {
@@ -2602,10 +2627,7 @@ var StormcloudVideoPlayer = class {
2602
2627
  this.currentAdIndex = 0;
2603
2628
  this.totalAdsInBreak = 1;
2604
2629
  if (this.config.debugAdTiming) {
2605
- console.log(
2606
- "[StormcloudVideoPlayer] Using VAST endpoint:",
2607
- vastTagUrl
2608
- );
2630
+ console.log("[StormcloudVideoPlayer] Using VAST endpoint:", vastTagUrl);
2609
2631
  }
2610
2632
  } else if (tags && tags.length > 0) {
2611
2633
  vastTagUrl = tags[0];
@@ -2757,15 +2779,21 @@ var StormcloudVideoPlayer = class {
2757
2779
  await this.ima.requestAds(vastTagUrl);
2758
2780
  try {
2759
2781
  if (this.config.debugAdTiming) {
2760
- console.log("[StormcloudVideoPlayer] Ad request completed, attempting playback");
2782
+ console.log(
2783
+ "[StormcloudVideoPlayer] Ad request completed, attempting playback"
2784
+ );
2761
2785
  }
2762
2786
  await this.ima.play();
2763
2787
  if (this.config.debugAdTiming) {
2764
- console.log("[StormcloudVideoPlayer] Ad playback started successfully");
2788
+ console.log(
2789
+ "[StormcloudVideoPlayer] Ad playback started successfully"
2790
+ );
2765
2791
  }
2766
2792
  } catch (playError) {
2767
2793
  if (this.config.debugAdTiming) {
2768
- console.log("[StormcloudVideoPlayer] No ads available, skipping playback");
2794
+ console.log(
2795
+ "[StormcloudVideoPlayer] No ads available, skipping playback"
2796
+ );
2769
2797
  }
2770
2798
  this.handleAdFailure();
2771
2799
  return;
@@ -2821,7 +2849,9 @@ var StormcloudVideoPlayer = class {
2821
2849
  });
2822
2850
  } else {
2823
2851
  if (this.config.debugAdTiming) {
2824
- console.log("[StormcloudVideoPlayer] Video is already playing, no resume needed");
2852
+ console.log(
2853
+ "[StormcloudVideoPlayer] Video is already playing, no resume needed"
2854
+ );
2825
2855
  }
2826
2856
  }
2827
2857
  }
@@ -2840,7 +2870,11 @@ var StormcloudVideoPlayer = class {
2840
2870
  if (this.config.debugAdTiming) {
2841
2871
  console.warn(
2842
2872
  "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume",
2843
- { paused: this.video.paused, showAds: this.showAds, adPlaying: this.ima.isAdPlaying() }
2873
+ {
2874
+ paused: this.video.paused,
2875
+ showAds: this.showAds,
2876
+ adPlaying: this.ima.isAdPlaying()
2877
+ }
2844
2878
  );
2845
2879
  }
2846
2880
  this.handleAdFailure();
@@ -3033,10 +3067,20 @@ var HlsPlayer = class extends import_react2.Component {
3033
3067
  }
3034
3068
  };
3035
3069
  this.play = () => {
3036
- var _a, _b;
3070
+ var _a, _b, _c;
3037
3071
  if (this.props.videoElement) {
3038
- this.props.videoElement.play();
3039
- (_b = (_a = this.props).onPlay) == null ? void 0 : _b.call(_a);
3072
+ const video = this.props.videoElement;
3073
+ const hasValidSource = video.src || video.currentSrc && video.currentSrc !== "" || video.readyState >= 1;
3074
+ if (hasValidSource) {
3075
+ (_a = video.play()) == null ? void 0 : _a.catch((error) => {
3076
+ var _a2, _b2;
3077
+ console.error("[HlsPlayer] Failed to play:", error);
3078
+ (_b2 = (_a2 = this.props).onError) == null ? void 0 : _b2.call(_a2, error);
3079
+ });
3080
+ (_c = (_b = this.props).onPlay) == null ? void 0 : _c.call(_b);
3081
+ } else {
3082
+ console.warn("[HlsPlayer] Cannot play: video has no valid source");
3083
+ }
3040
3084
  }
3041
3085
  };
3042
3086
  this.pause = () => {
@@ -3205,8 +3249,19 @@ var FilePlayer = class extends import_react3.Component {
3205
3249
  };
3206
3250
  };
3207
3251
  this.play = () => {
3252
+ var _a;
3208
3253
  if (this.props.videoElement) {
3209
- this.props.videoElement.play();
3254
+ const video = this.props.videoElement;
3255
+ const hasValidSource = video.src || video.currentSrc && video.currentSrc !== "" || video.readyState >= 1;
3256
+ if (hasValidSource) {
3257
+ (_a = video.play()) == null ? void 0 : _a.catch((error) => {
3258
+ var _a2, _b;
3259
+ console.error("[FilePlayer] Failed to play:", error);
3260
+ (_b = (_a2 = this.props).onError) == null ? void 0 : _b.call(_a2, error);
3261
+ });
3262
+ } else {
3263
+ console.warn("[FilePlayer] Cannot play: video has no valid source");
3264
+ }
3210
3265
  }
3211
3266
  };
3212
3267
  this.pause = () => {