stormcloud-video-player 0.6.3 → 0.6.5

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.
@@ -618,6 +618,7 @@ function createVastAdLayer(contentVideo, options) {
618
618
  var destroyed = false;
619
619
  var tornDown = false;
620
620
  var trackingFired = createEmptyTrackingState();
621
+ var adStallTimerId;
621
622
  var currentAdEventHandlers;
622
623
  var preloadSlots = /* @__PURE__ */ new Map();
623
624
  function emit(event, payload) {
@@ -691,6 +692,14 @@ function createVastAdLayer(contentVideo, options) {
691
692
  } else if (debug) {
692
693
  console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
693
694
  }
695
+ } else {
696
+ var mp4Only1 = candidates.filter(function(f) {
697
+ return !isHlsMediaFile(f);
698
+ });
699
+ if (mp4Only1.length > 0) {
700
+ candidates = mp4Only1;
701
+ if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
702
+ }
694
703
  }
695
704
  var firstFile = candidates[0];
696
705
  if (candidates.length === 1) return firstFile;
@@ -733,7 +742,14 @@ function createVastAdLayer(contentVideo, options) {
733
742
  video.volume = 1;
734
743
  return video;
735
744
  }
745
+ function clearAdStallTimer() {
746
+ if (adStallTimerId != null) {
747
+ clearTimeout(adStallTimerId);
748
+ adStallTimerId = void 0;
749
+ }
750
+ }
736
751
  function removeAdEventListeners() {
752
+ clearAdStallTimer();
737
753
  if (!currentAdEventHandlers || !adVideoElement) return;
738
754
  var el = adVideoElement;
739
755
  el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
@@ -743,6 +759,7 @@ function createVastAdLayer(contentVideo, options) {
743
759
  el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
744
760
  el.removeEventListener("pause", currentAdEventHandlers.pause);
745
761
  el.removeEventListener("play", currentAdEventHandlers.play);
762
+ el.removeEventListener("waiting", currentAdEventHandlers.waiting);
746
763
  currentAdEventHandlers = void 0;
747
764
  }
748
765
  function setupAdEventListeners() {
@@ -767,6 +784,7 @@ function createVastAdLayer(contentVideo, options) {
767
784
  }
768
785
  },
769
786
  playing: function playing() {
787
+ clearAdStallTimer();
770
788
  var ad = currentAd;
771
789
  if (!ad || trackingFired.start) return;
772
790
  trackingFired.start = true;
@@ -803,6 +821,16 @@ function createVastAdLayer(contentVideo, options) {
803
821
  if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
804
822
  fireTrackingPixels2(currentAd.trackingUrls.resume);
805
823
  }
824
+ },
825
+ waiting: function waiting() {
826
+ clearAdStallTimer();
827
+ adStallTimerId = setTimeout(function() {
828
+ adStallTimerId = void 0;
829
+ if (adPlaying) {
830
+ if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
831
+ handleAdError();
832
+ }
833
+ }, 8e3);
806
834
  }
807
835
  };
808
836
  adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
@@ -812,6 +840,7 @@ function createVastAdLayer(contentVideo, options) {
812
840
  adVideoElement.addEventListener("volumechange", handlers.volumechange);
813
841
  adVideoElement.addEventListener("pause", handlers.pause);
814
842
  adVideoElement.addEventListener("play", handlers.play);
843
+ adVideoElement.addEventListener("waiting", handlers.waiting);
815
844
  currentAdEventHandlers = handlers;
816
845
  }
817
846
  function setAdPlayingFlag(isPlaying) {
@@ -823,6 +852,7 @@ function createVastAdLayer(contentVideo, options) {
823
852
  }
824
853
  function handleAdComplete() {
825
854
  if (tornDown) return;
855
+ clearAdStallTimer();
826
856
  if (debug) console.log("".concat(LOG, " Handling ad completion"));
827
857
  adPlaying = false;
828
858
  setAdPlayingFlag(false);
@@ -836,6 +866,7 @@ function createVastAdLayer(contentVideo, options) {
836
866
  function handleAdError() {
837
867
  if (tornDown) return;
838
868
  if (!adPlaying) return;
869
+ clearAdStallTimer();
839
870
  if (debug) console.log("".concat(LOG, " Handling ad error"));
840
871
  adPlaying = false;
841
872
  setAdPlayingFlag(false);
@@ -886,6 +917,7 @@ function createVastAdLayer(contentVideo, options) {
886
917
  adHls.loadSource(mediaFile.url);
887
918
  adHls.attachMedia(adVideoElement);
888
919
  adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
920
+ if (!adPlaying) return;
889
921
  adVideoElement.play().catch(function(error) {
890
922
  console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
891
923
  handleAdError();
@@ -1519,6 +1551,7 @@ function createVastAdLayer(contentVideo, options) {
1519
1551
  return 1;
1520
1552
  },
1521
1553
  showPlaceholder: function showPlaceholder() {
1554
+ if (singleElementMode) return;
1522
1555
  contentVideo.style.opacity = "0";
1523
1556
  contentVideo.style.visibility = "hidden";
1524
1557
  if (!adContainerEl) {