stormcloud-video-player 0.3.59 → 0.3.60

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.
package/lib/index.cjs CHANGED
@@ -1935,6 +1935,16 @@ function createHlsAdPlayer(contentVideo, options) {
1935
1935
  });
1936
1936
  return bestMatch.file;
1937
1937
  }
1938
+ function isHlsMediaFile(mediaFile) {
1939
+ var type = mediaFile.type.toLowerCase();
1940
+ var url = mediaFile.url.toLowerCase();
1941
+ return type === "application/x-mpegurl" || type === "application/vnd.apple.mpegurl" || type.includes("mpegurl") || url.includes(".m3u8");
1942
+ }
1943
+ function isProgressiveMediaFile(mediaFile) {
1944
+ var type = mediaFile.type.toLowerCase();
1945
+ var url = mediaFile.url.toLowerCase();
1946
+ return type.startsWith("video/") || url.endsWith(".mp4") || url.includes(".mp4?");
1947
+ }
1938
1948
  function parseVastXml(xmlString) {
1939
1949
  try {
1940
1950
  var _xmlDoc_querySelector, _xmlDoc_querySelector1, _xmlDoc_querySelector_textContent, _xmlDoc_querySelector2;
@@ -1966,30 +1976,32 @@ function createHlsAdPlayer(contentVideo, options) {
1966
1976
  var width = mf.getAttribute("width") || "";
1967
1977
  var height = mf.getAttribute("height") || "";
1968
1978
  console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1969
- if (type === "application/x-mpegURL" || type.includes("m3u8")) {
1970
- if (!url) {
1971
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has HLS type but empty URL"));
1972
- return;
1973
- }
1974
- var bitrateAttr = mf.getAttribute("bitrate");
1975
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1976
- mediaFiles.push({
1977
- url: url,
1978
- type: type,
1979
- width: parseInt(width || "1920", 10),
1980
- height: parseInt(height || "1080", 10),
1981
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1982
- });
1983
- console.log("[HlsAdPlayer] Added HLS MediaFile: ".concat(url));
1979
+ var mediaFile = {
1980
+ url: url,
1981
+ type: type,
1982
+ width: parseInt(width || "1920", 10),
1983
+ height: parseInt(height || "1080", 10),
1984
+ bitrate: void 0
1985
+ };
1986
+ if (!url) {
1987
+ console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1988
+ return;
1989
+ }
1990
+ var bitrateAttr = mf.getAttribute("bitrate");
1991
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1992
+ mediaFile.bitrate = bitrateValue && bitrateValue > 0 ? bitrateValue : void 0;
1993
+ if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1994
+ mediaFiles.push(mediaFile);
1995
+ console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1984
1996
  } else {
1985
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not HLS)'));
1997
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1986
1998
  }
1987
1999
  });
1988
2000
  if (mediaFiles.length === 0) {
1989
2001
  if (isNoAdAvailable) {
1990
2002
  console.warn("[HlsAdPlayer] No ads available (VAST response indicates no ads)");
1991
2003
  } else {
1992
- console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
2004
+ console.warn("[HlsAdPlayer] No supported media files found in VAST XML");
1993
2005
  }
1994
2006
  return null;
1995
2007
  }
@@ -2286,7 +2298,7 @@ function createHlsAdPlayer(contentVideo, options) {
2286
2298
  },
2287
2299
  play: function play() {
2288
2300
  return _async_to_generator(function() {
2289
- var contentVolume, adVolume, mediaFile;
2301
+ var contentVolume, adVolume, mediaFile, isHlsAd;
2290
2302
  return _ts_generator(this, function(_state) {
2291
2303
  if (!currentAd) {
2292
2304
  console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
@@ -2338,8 +2350,9 @@ function createHlsAdPlayer(contentVideo, options) {
2338
2350
  if (!mediaFile) {
2339
2351
  throw new Error("No media file available for ad");
2340
2352
  }
2341
- console.log("[HlsAdPlayer] Loading ad from: ".concat(mediaFile.url));
2342
- if (import_hls.default.isSupported()) {
2353
+ isHlsAd = isHlsMediaFile(mediaFile);
2354
+ console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad from: ").concat(mediaFile.url));
2355
+ if (isHlsAd && import_hls.default.isSupported()) {
2343
2356
  if (adHls) {
2344
2357
  adHls.destroy();
2345
2358
  }
@@ -2362,14 +2375,25 @@ function createHlsAdPlayer(contentVideo, options) {
2362
2375
  handleAdError();
2363
2376
  }
2364
2377
  });
2365
- } else if (adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2378
+ } else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2366
2379
  adVideoElement.src = mediaFile.url;
2367
2380
  adVideoElement.play().catch(function(error) {
2368
2381
  console.error("[HlsAdPlayer] Error starting ad playback:", error);
2369
2382
  handleAdError();
2370
2383
  });
2384
+ } else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
2385
+ if (adHls) {
2386
+ adHls.destroy();
2387
+ adHls = void 0;
2388
+ }
2389
+ adVideoElement.src = mediaFile.url;
2390
+ adVideoElement.load();
2391
+ adVideoElement.play().catch(function(error) {
2392
+ console.error("[HlsAdPlayer] Error starting progressive ad playback:", error);
2393
+ handleAdError();
2394
+ });
2371
2395
  } else {
2372
- throw new Error("HLS not supported");
2396
+ throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
2373
2397
  }
2374
2398
  return [
2375
2399
  2,