@scarlett-player/hls 1.13.0 → 1.15.0

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.
@@ -358,7 +358,7 @@ function setupHlsEventHandlers(hls, api, callbacks) {
358
358
  api.setState("currentAudioTrack", null);
359
359
  };
360
360
  }
361
- function setupVideoEventHandlers(video, api, getLiveMetrics) {
361
+ function setupVideoEventHandlers(video, api, getLiveMetrics, gate) {
362
362
  const handlers = [];
363
363
  const addHandler = (event, handler) => {
364
364
  video.addEventListener(event, handler);
@@ -380,11 +380,23 @@ function setupVideoEventHandlers(video, api, getLiveMetrics) {
380
380
  api.setState("buffering", false);
381
381
  api.setState("playbackState", "playing");
382
382
  syncEndedFromElement();
383
+ if (gate) gate.corePauseRequested = false;
384
+ if (gate?.corePlayRequested) {
385
+ gate.corePlayRequested = false;
386
+ } else {
387
+ api.emit("playback:play", void 0);
388
+ }
383
389
  });
384
390
  addHandler("pause", () => {
385
391
  api.setState("playing", false);
386
392
  api.setState("paused", true);
387
393
  api.setState("playbackState", "paused");
394
+ if (gate) gate.corePlayRequested = false;
395
+ if (gate?.corePauseRequested) {
396
+ gate.corePauseRequested = false;
397
+ } else {
398
+ api.emit("playback:pause", void 0);
399
+ }
388
400
  });
389
401
  addHandler("ended", () => {
390
402
  api.setState("playing", false);
@@ -654,7 +666,7 @@ function createValidatingPlaylistLoader(Hls) {
654
666
  }
655
667
 
656
668
  // src/version.ts
657
- var PKG_VERSION = true ? "1.12.0" : "0.0.0-dev";
669
+ var PKG_VERSION = true ? "1.14.0" : "0.0.0-dev";
658
670
 
659
671
  // src/create-hls-plugin.ts
660
672
  var DEFAULT_CONFIG = {
@@ -698,6 +710,10 @@ function createHLSPluginWith(loader, variant, config) {
698
710
  let cleanupHlsEvents = null;
699
711
  let cleanupVideoEvents = null;
700
712
  let isAutoQuality = true;
713
+ const playbackGate = {
714
+ corePlayRequested: false,
715
+ corePauseRequested: false
716
+ };
701
717
  let mediaTypeClassifier = null;
702
718
  let lastLevelDetails = null;
703
719
  let lastLiveMetrics = null;
@@ -1054,7 +1070,7 @@ function createHLSPluginWith(loader, variant, config) {
1054
1070
  const videoEl = getOrCreateVideo();
1055
1071
  isNative = true;
1056
1072
  if (api) {
1057
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1073
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1058
1074
  }
1059
1075
  mediaTypeClassifier?.beginSource(src);
1060
1076
  mediaTypeClassifier?.attach(videoEl);
@@ -1149,7 +1165,7 @@ function createHLSPluginWith(loader, variant, config) {
1149
1165
  isNative = false;
1150
1166
  hls = loader.createHlsInstance(buildHlsConfig());
1151
1167
  if (api) {
1152
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1168
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1153
1169
  }
1154
1170
  mediaTypeClassifier?.beginSource(src);
1155
1171
  mediaTypeClassifier?.attach(videoEl);
@@ -1443,14 +1459,27 @@ function createHLSPluginWith(loader, variant, config) {
1443
1459
  mediaTypeClassifier = createMediaTypeClassifier(api);
1444
1460
  const unsubPlay = api.on("playback:play", async () => {
1445
1461
  if (!video) return;
1462
+ if (!video.paused) return;
1446
1463
  try {
1464
+ playbackGate.corePlayRequested = true;
1447
1465
  await video.play();
1448
1466
  } catch (e) {
1467
+ playbackGate.corePlayRequested = false;
1449
1468
  api?.logger.error("Play failed", e);
1450
1469
  }
1451
1470
  });
1452
1471
  const unsubPause = api.on("playback:pause", () => {
1453
- video?.pause();
1472
+ if (!video) return;
1473
+ if (video.paused) {
1474
+ if (playbackGate.corePlayRequested) {
1475
+ playbackGate.corePlayRequested = false;
1476
+ video.pause();
1477
+ }
1478
+ return;
1479
+ }
1480
+ playbackGate.corePauseRequested = true;
1481
+ playbackGate.corePlayRequested = false;
1482
+ video.pause();
1454
1483
  });
1455
1484
  const unsubSeek = api.on("playback:seeking", ({ time }) => {
1456
1485
  if (!video) return;
@@ -1594,6 +1623,8 @@ function createHLSPluginWith(loader, variant, config) {
1594
1623
  api.setState("live", false);
1595
1624
  cleanup(new Error("HLS load cancelled: superseded by a new load"));
1596
1625
  currentSrc = src;
1626
+ playbackGate.corePlayRequested = false;
1627
+ playbackGate.corePauseRequested = false;
1597
1628
  applyPoster();
1598
1629
  api.setState("playbackState", "loading");
1599
1630
  api.setState("buffering", true);
package/dist/index.cjs CHANGED
@@ -458,7 +458,7 @@ function setupHlsEventHandlers(hls, api, callbacks) {
458
458
  api.setState("currentAudioTrack", null);
459
459
  };
460
460
  }
461
- function setupVideoEventHandlers(video, api, getLiveMetrics) {
461
+ function setupVideoEventHandlers(video, api, getLiveMetrics, gate) {
462
462
  const handlers = [];
463
463
  const addHandler = (event, handler) => {
464
464
  video.addEventListener(event, handler);
@@ -480,11 +480,23 @@ function setupVideoEventHandlers(video, api, getLiveMetrics) {
480
480
  api.setState("buffering", false);
481
481
  api.setState("playbackState", "playing");
482
482
  syncEndedFromElement();
483
+ if (gate) gate.corePauseRequested = false;
484
+ if (gate?.corePlayRequested) {
485
+ gate.corePlayRequested = false;
486
+ } else {
487
+ api.emit("playback:play", void 0);
488
+ }
483
489
  });
484
490
  addHandler("pause", () => {
485
491
  api.setState("playing", false);
486
492
  api.setState("paused", true);
487
493
  api.setState("playbackState", "paused");
494
+ if (gate) gate.corePlayRequested = false;
495
+ if (gate?.corePauseRequested) {
496
+ gate.corePauseRequested = false;
497
+ } else {
498
+ api.emit("playback:pause", void 0);
499
+ }
488
500
  });
489
501
  addHandler("ended", () => {
490
502
  api.setState("playing", false);
@@ -754,7 +766,7 @@ function createValidatingPlaylistLoader(Hls) {
754
766
  }
755
767
 
756
768
  // src/version.ts
757
- var PKG_VERSION = true ? "1.12.0" : "0.0.0-dev";
769
+ var PKG_VERSION = true ? "1.14.0" : "0.0.0-dev";
758
770
 
759
771
  // src/create-hls-plugin.ts
760
772
  var DEFAULT_CONFIG = {
@@ -798,6 +810,10 @@ function createHLSPluginWith(loader, variant, config) {
798
810
  let cleanupHlsEvents = null;
799
811
  let cleanupVideoEvents = null;
800
812
  let isAutoQuality = true;
813
+ const playbackGate = {
814
+ corePlayRequested: false,
815
+ corePauseRequested: false
816
+ };
801
817
  let mediaTypeClassifier = null;
802
818
  let lastLevelDetails = null;
803
819
  let lastLiveMetrics = null;
@@ -1154,7 +1170,7 @@ function createHLSPluginWith(loader, variant, config) {
1154
1170
  const videoEl = getOrCreateVideo();
1155
1171
  isNative = true;
1156
1172
  if (api) {
1157
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1173
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1158
1174
  }
1159
1175
  mediaTypeClassifier?.beginSource(src);
1160
1176
  mediaTypeClassifier?.attach(videoEl);
@@ -1249,7 +1265,7 @@ function createHLSPluginWith(loader, variant, config) {
1249
1265
  isNative = false;
1250
1266
  hls = loader.createHlsInstance(buildHlsConfig());
1251
1267
  if (api) {
1252
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1268
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1253
1269
  }
1254
1270
  mediaTypeClassifier?.beginSource(src);
1255
1271
  mediaTypeClassifier?.attach(videoEl);
@@ -1543,14 +1559,27 @@ function createHLSPluginWith(loader, variant, config) {
1543
1559
  mediaTypeClassifier = createMediaTypeClassifier(api);
1544
1560
  const unsubPlay = api.on("playback:play", async () => {
1545
1561
  if (!video) return;
1562
+ if (!video.paused) return;
1546
1563
  try {
1564
+ playbackGate.corePlayRequested = true;
1547
1565
  await video.play();
1548
1566
  } catch (e) {
1567
+ playbackGate.corePlayRequested = false;
1549
1568
  api?.logger.error("Play failed", e);
1550
1569
  }
1551
1570
  });
1552
1571
  const unsubPause = api.on("playback:pause", () => {
1553
- video?.pause();
1572
+ if (!video) return;
1573
+ if (video.paused) {
1574
+ if (playbackGate.corePlayRequested) {
1575
+ playbackGate.corePlayRequested = false;
1576
+ video.pause();
1577
+ }
1578
+ return;
1579
+ }
1580
+ playbackGate.corePauseRequested = true;
1581
+ playbackGate.corePlayRequested = false;
1582
+ video.pause();
1554
1583
  });
1555
1584
  const unsubSeek = api.on("playback:seeking", ({ time }) => {
1556
1585
  if (!video) return;
@@ -1694,6 +1723,8 @@ function createHLSPluginWith(loader, variant, config) {
1694
1723
  api.setState("live", false);
1695
1724
  cleanup(new Error("HLS load cancelled: superseded by a new load"));
1696
1725
  currentSrc = src;
1726
+ playbackGate.corePlayRequested = false;
1727
+ playbackGate.corePauseRequested = false;
1697
1728
  applyPoster();
1698
1729
  api.setState("playbackState", "loading");
1699
1730
  api.setState("buffering", true);
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  computeLiveMetrics,
5
5
  createHLSPluginWith,
6
6
  sanitizeUrl
7
- } from "./chunk-3KFYKCR2.js";
7
+ } from "./chunk-P7BQ7EJF.js";
8
8
 
9
9
  // src/hls-loader.ts
10
10
  var hls_loader_exports = {};
package/dist/light.cjs CHANGED
@@ -458,7 +458,7 @@ function setupHlsEventHandlers(hls, api, callbacks) {
458
458
  api.setState("currentAudioTrack", null);
459
459
  };
460
460
  }
461
- function setupVideoEventHandlers(video, api, getLiveMetrics) {
461
+ function setupVideoEventHandlers(video, api, getLiveMetrics, gate) {
462
462
  const handlers = [];
463
463
  const addHandler = (event, handler) => {
464
464
  video.addEventListener(event, handler);
@@ -480,11 +480,23 @@ function setupVideoEventHandlers(video, api, getLiveMetrics) {
480
480
  api.setState("buffering", false);
481
481
  api.setState("playbackState", "playing");
482
482
  syncEndedFromElement();
483
+ if (gate) gate.corePauseRequested = false;
484
+ if (gate?.corePlayRequested) {
485
+ gate.corePlayRequested = false;
486
+ } else {
487
+ api.emit("playback:play", void 0);
488
+ }
483
489
  });
484
490
  addHandler("pause", () => {
485
491
  api.setState("playing", false);
486
492
  api.setState("paused", true);
487
493
  api.setState("playbackState", "paused");
494
+ if (gate) gate.corePlayRequested = false;
495
+ if (gate?.corePauseRequested) {
496
+ gate.corePauseRequested = false;
497
+ } else {
498
+ api.emit("playback:pause", void 0);
499
+ }
488
500
  });
489
501
  addHandler("ended", () => {
490
502
  api.setState("playing", false);
@@ -754,7 +766,7 @@ function createValidatingPlaylistLoader(Hls) {
754
766
  }
755
767
 
756
768
  // src/version.ts
757
- var PKG_VERSION = true ? "1.12.0" : "0.0.0-dev";
769
+ var PKG_VERSION = true ? "1.14.0" : "0.0.0-dev";
758
770
 
759
771
  // src/create-hls-plugin.ts
760
772
  var DEFAULT_CONFIG = {
@@ -798,6 +810,10 @@ function createHLSPluginWith(loader, variant, config) {
798
810
  let cleanupHlsEvents = null;
799
811
  let cleanupVideoEvents = null;
800
812
  let isAutoQuality = true;
813
+ const playbackGate = {
814
+ corePlayRequested: false,
815
+ corePauseRequested: false
816
+ };
801
817
  let mediaTypeClassifier = null;
802
818
  let lastLevelDetails = null;
803
819
  let lastLiveMetrics = null;
@@ -1154,7 +1170,7 @@ function createHLSPluginWith(loader, variant, config) {
1154
1170
  const videoEl = getOrCreateVideo();
1155
1171
  isNative = true;
1156
1172
  if (api) {
1157
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1173
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1158
1174
  }
1159
1175
  mediaTypeClassifier?.beginSource(src);
1160
1176
  mediaTypeClassifier?.attach(videoEl);
@@ -1249,7 +1265,7 @@ function createHLSPluginWith(loader, variant, config) {
1249
1265
  isNative = false;
1250
1266
  hls = loader.createHlsInstance(buildHlsConfig());
1251
1267
  if (api) {
1252
- cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics);
1268
+ cleanupVideoEvents = setupVideoEventHandlers(videoEl, api, readLiveMetrics, playbackGate);
1253
1269
  }
1254
1270
  mediaTypeClassifier?.beginSource(src);
1255
1271
  mediaTypeClassifier?.attach(videoEl);
@@ -1543,14 +1559,27 @@ function createHLSPluginWith(loader, variant, config) {
1543
1559
  mediaTypeClassifier = createMediaTypeClassifier(api);
1544
1560
  const unsubPlay = api.on("playback:play", async () => {
1545
1561
  if (!video) return;
1562
+ if (!video.paused) return;
1546
1563
  try {
1564
+ playbackGate.corePlayRequested = true;
1547
1565
  await video.play();
1548
1566
  } catch (e) {
1567
+ playbackGate.corePlayRequested = false;
1549
1568
  api?.logger.error("Play failed", e);
1550
1569
  }
1551
1570
  });
1552
1571
  const unsubPause = api.on("playback:pause", () => {
1553
- video?.pause();
1572
+ if (!video) return;
1573
+ if (video.paused) {
1574
+ if (playbackGate.corePlayRequested) {
1575
+ playbackGate.corePlayRequested = false;
1576
+ video.pause();
1577
+ }
1578
+ return;
1579
+ }
1580
+ playbackGate.corePauseRequested = true;
1581
+ playbackGate.corePlayRequested = false;
1582
+ video.pause();
1554
1583
  });
1555
1584
  const unsubSeek = api.on("playback:seeking", ({ time }) => {
1556
1585
  if (!video) return;
@@ -1694,6 +1723,8 @@ function createHLSPluginWith(loader, variant, config) {
1694
1723
  api.setState("live", false);
1695
1724
  cleanup(new Error("HLS load cancelled: superseded by a new load"));
1696
1725
  currentSrc = src;
1726
+ playbackGate.corePlayRequested = false;
1727
+ playbackGate.corePauseRequested = false;
1697
1728
  applyPoster();
1698
1729
  api.setState("playbackState", "loading");
1699
1730
  api.setState("buffering", true);
package/dist/light.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  computeLiveMetrics,
5
5
  createHLSPluginWith,
6
6
  sanitizeUrl
7
- } from "./chunk-3KFYKCR2.js";
7
+ } from "./chunk-P7BQ7EJF.js";
8
8
 
9
9
  // src/hls-loader-light.ts
10
10
  var hls_loader_light_exports = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/hls",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "HLS Provider Plugin for Scarlett Player",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -37,7 +37,7 @@
37
37
  "vitest": "^1.6.0",
38
38
  "@vitest/coverage-v8": "^1.6.0",
39
39
  "jsdom": "^24.0.0",
40
- "@scarlett-player/core": "1.13.0"
40
+ "@scarlett-player/core": "1.15.0"
41
41
  },
42
42
  "keywords": [
43
43
  "video",