stormcloud-video-player 0.8.44 → 0.8.46

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.
@@ -1,5 +1,5 @@
1
1
  import Hls from 'hls.js';
2
- import { S as StormcloudVideoPlayerConfig, a as Scte35Marker } from '../types-iDjS8f_7.cjs';
2
+ import { a as StormcloudVideoPlayerConfig, S as Scte35Marker } from '../types-cTqIKw_D.cjs';
3
3
  import { Scte35CueContext } from './playerTypes.cjs';
4
4
  import { Scte35CueManager } from './Scte35CueManager.cjs';
5
5
  import { AdTimingService } from './AdTimingService.cjs';
@@ -35,6 +35,7 @@ declare class HlsEngine {
35
35
  private processFragmentScte35Payload;
36
36
  getLiveSyncPosition(): number | undefined;
37
37
  restartLoadAt(position: number): void;
38
+ recoverMediaError(): void;
38
39
  reloadLiveStream(): void;
39
40
  destroy(): void;
40
41
  }
@@ -1,4 +1,4 @@
1
- import { A as AdController } from '../types-iDjS8f_7.cjs';
1
+ import { A as AdController } from '../types-cTqIKw_D.cjs';
2
2
 
3
3
  declare function getAdAudioVolume(adPlayer: AdController): number;
4
4
  declare function toggleMute(video: HTMLVideoElement, adPlayer: AdController, debug: boolean): void;
@@ -1,4 +1,4 @@
1
- import { a as Scte35Marker } from '../types-iDjS8f_7.cjs';
1
+ import { S as Scte35Marker } from '../types-cTqIKw_D.cjs';
2
2
  import { Scte35CueSource, Scte35CueReadiness, Scte35CueContext } from './playerTypes.cjs';
3
3
 
4
4
  interface Scte35CueManagerCallbacks {
@@ -1,4 +1,4 @@
1
- import { a as Scte35Marker, I as Id3TagInfo } from '../types-iDjS8f_7.cjs';
1
+ import { S as Scte35Marker, I as Id3TagInfo } from '../types-cTqIKw_D.cjs';
2
2
 
3
3
  declare function parseCueOutDuration(value: string): number | undefined;
4
4
  declare function parseCueOutCont(value: string): {
@@ -1205,16 +1205,34 @@ function createHlsAdPlayer(contentVideo, options) {
1205
1205
  }
1206
1206
  }, STALL_CHECK_INTERVAL_MS);
1207
1207
  }
1208
+ function releaseAdDecoder() {
1209
+ if (adHls) {
1210
+ adHls.destroy();
1211
+ adHls = void 0;
1212
+ }
1213
+ if (adVideoElement) {
1214
+ adVideoElement.pause();
1215
+ adVideoElement.removeAttribute("src");
1216
+ try {
1217
+ adVideoElement.load();
1218
+ } catch (error) {
1219
+ console.warn("[HlsAdPlayer] adVideoElement.load() threw after src removal:", error);
1220
+ }
1221
+ adVideoElement.remove();
1222
+ adVideoElement = void 0;
1223
+ }
1224
+ if (adContainerEl) {
1225
+ adContainerEl.style.display = "none";
1226
+ adContainerEl.style.pointerEvents = "none";
1227
+ }
1228
+ }
1208
1229
  function handleAdComplete() {
1209
1230
  console.log("[HlsAdPlayer] Handling ad completion");
1210
1231
  clearStallWatchdog();
1211
1232
  adPlaying = false;
1212
1233
  setAdPlayingFlag(false);
1213
1234
  contentVideo.muted = true;
1214
- if (adContainerEl) {
1215
- adContainerEl.style.display = "none";
1216
- adContainerEl.style.pointerEvents = "none";
1217
- }
1235
+ releaseAdDecoder();
1218
1236
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1219
1237
  contentVideo.style.visibility = "visible";
1220
1238
  contentVideo.style.opacity = "1";
@@ -1222,7 +1240,9 @@ function createHlsAdPlayer(contentVideo, options) {
1222
1240
  if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1223
1241
  if (contentVideo.paused) {
1224
1242
  console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback");
1225
- contentVideo.play().catch(function() {});
1243
+ contentVideo.play().catch(function(error) {
1244
+ console.error("[HlsAdPlayer] Error resuming content playback in live mode:", error);
1245
+ });
1226
1246
  } else {
1227
1247
  console.log("[HlsAdPlayer] Content video already playing in live mode");
1228
1248
  }
@@ -1235,10 +1255,7 @@ function createHlsAdPlayer(contentVideo, options) {
1235
1255
  adPlaying = false;
1236
1256
  setAdPlayingFlag(false);
1237
1257
  contentVideo.muted = true;
1238
- if (adContainerEl) {
1239
- adContainerEl.style.display = "none";
1240
- adContainerEl.style.pointerEvents = "none";
1241
- }
1258
+ releaseAdDecoder();
1242
1259
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1243
1260
  contentVideo.style.visibility = "visible";
1244
1261
  contentVideo.style.opacity = "1";
@@ -1447,29 +1464,17 @@ function createHlsAdPlayer(contentVideo, options) {
1447
1464
  contentVideo.muted = originalMutedState;
1448
1465
  contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1449
1466
  console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState, ", volume: ").concat(contentVideo.volume));
1450
- if (adContainerEl) {
1451
- adContainerEl.style.display = "none";
1452
- adContainerEl.style.pointerEvents = "none";
1453
- }
1467
+ releaseAdDecoder();
1454
1468
  contentVideo.style.visibility = "visible";
1455
1469
  contentVideo.style.opacity = "1";
1456
1470
  if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1457
1471
  if (contentVideo.paused) {
1458
1472
  console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback on stop");
1459
- contentVideo.play().catch(function() {});
1473
+ contentVideo.play().catch(function(error) {
1474
+ console.error("[HlsAdPlayer] Error resuming content playback in live mode on stop:", error);
1475
+ });
1460
1476
  }
1461
1477
  }
1462
- if (adHls) {
1463
- adHls.destroy();
1464
- adHls = void 0;
1465
- }
1466
- if (adVideoElement) {
1467
- adVideoElement.pause();
1468
- adVideoElement.removeAttribute("src");
1469
- try {
1470
- adVideoElement.load();
1471
- } catch (unused) {}
1472
- }
1473
1478
  currentAd = void 0;
1474
1479
  podAds = [];
1475
1480
  podIndex = 0;
@@ -1508,19 +1513,7 @@ function createHlsAdPlayer(contentVideo, options) {
1508
1513
  setAdPlayingFlag(false);
1509
1514
  contentVideo.muted = originalMutedState;
1510
1515
  contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1511
- if (adHls) {
1512
- adHls.destroy();
1513
- adHls = void 0;
1514
- }
1515
- if (adVideoElement) {
1516
- adVideoElement.pause();
1517
- adVideoElement.removeAttribute("src");
1518
- try {
1519
- adVideoElement.load();
1520
- } catch (unused) {}
1521
- adVideoElement.remove();
1522
- adVideoElement = void 0;
1523
- }
1516
+ releaseAdDecoder();
1524
1517
  if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
1525
1518
  adContainerEl.parentElement.removeChild(adContainerEl);
1526
1519
  }
@@ -6680,6 +6673,21 @@ var HlsEngine = /*#__PURE__*/ function() {
6680
6673
  }
6681
6674
  }
6682
6675
  },
6676
+ {
6677
+ key: "recoverMediaError",
6678
+ value: function recoverMediaError() {
6679
+ if (!this.hls) {
6680
+ return;
6681
+ }
6682
+ try {
6683
+ this.hls.recoverMediaError();
6684
+ } catch (error) {
6685
+ if (this.debug) {
6686
+ console.warn("[StormcloudVideoPlayer] recoverMediaError() failed:", error);
6687
+ }
6688
+ }
6689
+ }
6690
+ },
6683
6691
  {
6684
6692
  key: "reloadLiveStream",
6685
6693
  value: function reloadLiveStream() {
@@ -6697,7 +6705,9 @@ var HlsEngine = /*#__PURE__*/ function() {
6697
6705
  try {
6698
6706
  this.video.removeAttribute("src");
6699
6707
  this.video.load();
6700
- } catch (unused) {}
6708
+ } catch (error) {
6709
+ console.warn("[StormcloudVideoPlayer] video.load() threw after src removal:", error);
6710
+ }
6701
6711
  hls.attachMedia(this.video);
6702
6712
  } catch (error) {
6703
6713
  this.reloadingLiveStream = false;
@@ -8081,8 +8091,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8081
8091
  var pollIntervalMs = 1e3;
8082
8092
  var graceMs = 5e3;
8083
8093
  var recoveryCooldownMs = 5e3;
8084
- var maxRecoveries = 2;
8085
- var maxMonitorMs = 3e4;
8094
+ var maxRecoveries = 3;
8095
+ var maxMonitorMs = 45e3;
8086
8096
  var startTime = Date.now();
8087
8097
  var baseline = resumeBaseline;
8088
8098
  var recoveries = 0;
@@ -8194,8 +8204,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8194
8204
  if (canRecover) {
8195
8205
  recoveries++;
8196
8206
  lastRecoveryAt = Date.now();
8197
- var isFinalAttempt = recoveries >= maxRecoveries;
8198
- if (!isFinalAttempt) {
8207
+ if (recoveries === 1) {
8208
+ if (_this.debug) {
8209
+ console.warn("[StormcloudVideoPlayer] Content wedged after ad break — calling recoverMediaError() (recovery ".concat(recoveries, "/").concat(maxRecoveries, ") — ").concat(_this.describeVideoState()));
8210
+ }
8211
+ _this.host.recoverMediaError();
8212
+ } else if (recoveries === 2) {
8199
8213
  var liveSyncPos = _this.host.getLiveSyncPosition();
8200
8214
  var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8201
8215
  if (_this.debug) {
@@ -8227,17 +8241,41 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8227
8241
  value: function resumeContentPlayback() {
8228
8242
  var _this = this;
8229
8243
  var attempt = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
8230
- var maxAttempts = 3;
8231
- if (!this.host.video.paused) {
8244
+ var maxAttempts = 5;
8245
+ var video = this.host.video;
8246
+ if (!video.paused) {
8232
8247
  if (this.debug && attempt === 0) {
8233
8248
  console.log("[StormcloudVideoPlayer] Content video already playing after ads");
8234
8249
  }
8235
8250
  return;
8236
8251
  }
8237
8252
  if (this.debug) {
8238
- console.log("[StormcloudVideoPlayer] Resuming content playback after ads (attempt ".concat(attempt + 1, "/").concat(maxAttempts, ")"));
8253
+ console.log("[StormcloudVideoPlayer] Resuming content playback after ads (attempt ".concat(attempt + 1, "/").concat(maxAttempts, ", readyState=").concat(video.readyState, ")"));
8239
8254
  }
8240
- var playResult = this.host.video.play();
8255
+ if (video.readyState < 3) {
8256
+ if (attempt + 1 >= maxAttempts) {
8257
+ var _video_play;
8258
+ if (this.debug) {
8259
+ console.warn("[StormcloudVideoPlayer] readyState never reached HAVE_FUTURE_DATA, forcing play()");
8260
+ }
8261
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8262
+ return;
8263
+ }
8264
+ var onReady = function onReady1() {
8265
+ video.removeEventListener("canplay", onReady);
8266
+ _this.resumeContentPlayback(attempt + 1);
8267
+ };
8268
+ video.addEventListener("canplay", onReady);
8269
+ var backoffMs = 500 * (attempt + 1);
8270
+ window.setTimeout(function() {
8271
+ video.removeEventListener("canplay", onReady);
8272
+ if (video.paused) {
8273
+ _this.resumeContentPlayback(attempt + 1);
8274
+ }
8275
+ }, backoffMs);
8276
+ return;
8277
+ }
8278
+ var playResult = video.play();
8241
8279
  if (playResult && typeof playResult.catch === "function") {
8242
8280
  playResult.catch(function(error) {
8243
8281
  if (attempt + 1 >= maxAttempts) {
@@ -8376,6 +8414,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8376
8414
  reloadLiveStream: function reloadLiveStream() {
8377
8415
  return _this.hlsEngine.reloadLiveStream();
8378
8416
  },
8417
+ recoverMediaError: function recoverMediaError() {
8418
+ return _this.hlsEngine.recoverMediaError();
8419
+ },
8379
8420
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8380
8421
  return _this.generatePodVastUrl(base, breakDurationMs);
8381
8422
  }