@nikelroot/video-player 0.2.0 → 0.2.1
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/README.md +13 -1
- package/dist/index.cjs +14 -1
- package/dist/index.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,19 @@ export function Example() {
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
When `active` is `true`, pressing `F` toggles fullscreen.
|
|
40
|
+
When `active` is `true`, pressing `F` toggles fullscreen. When `active` is `false`, the player releases its media source and waits until it becomes active again. In lists with several players, pass `active={index === activeIndex}` so inactive videos do not keep HLS/media pipelines open.
|
|
41
|
+
|
|
42
|
+
For public CDN-hosted videos, prefer non-credentialed requests unless the CDN is explicitly configured for cookies:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<VideoPlayer
|
|
46
|
+
videoSrc="https://cdn.example.com/stream.m3u8"
|
|
47
|
+
hlsCredentials="same-origin"
|
|
48
|
+
crossOrigin="anonymous"
|
|
49
|
+
/>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If you use `hlsCredentials="include"` or `crossOrigin="use-credentials"`, the CDN must allow credentialed CORS and should not forward `Cookie` into the cache key for public media.
|
|
41
53
|
|
|
42
54
|
Build before publishing:
|
|
43
55
|
|
package/dist/index.cjs
CHANGED
|
@@ -869,6 +869,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
869
869
|
const duration = durationProp != null ? durationProp : durationState;
|
|
870
870
|
const currentTime = currentTimeState;
|
|
871
871
|
const fullscreenAllowed = active != null ? active : true;
|
|
872
|
+
const shouldLoadMedia = active !== false;
|
|
872
873
|
const onTimeChangeRef = (0, import_react3.useRef)(onTimeChange);
|
|
873
874
|
const onDurationChangeRef = (0, import_react3.useRef)(onDurationChange);
|
|
874
875
|
onTimeChangeRef.current = onTimeChange;
|
|
@@ -1398,6 +1399,17 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1398
1399
|
liveStabilityMode.current = false;
|
|
1399
1400
|
liveStallEvents.current = [];
|
|
1400
1401
|
resetMediaForSourceChange();
|
|
1402
|
+
if (!shouldLoadMedia) {
|
|
1403
|
+
setTimeD.current.cancel();
|
|
1404
|
+
setCurrentTimeUi.current.cancel();
|
|
1405
|
+
setDurationState(0);
|
|
1406
|
+
setCurrentTimeState(0);
|
|
1407
|
+
setPlayingState(false);
|
|
1408
|
+
return () => {
|
|
1409
|
+
sourceLoadId.current += 1;
|
|
1410
|
+
resetMediaForSourceChange();
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1401
1413
|
if (sourceType === "native" || type === "video") loadVideoNative(loadId);
|
|
1402
1414
|
else if (sourceType === "hls") void loadVideo(initialTime, loadId);
|
|
1403
1415
|
else if (isLikelyHlsSource(videoSrc)) void loadVideoHls(loadId);
|
|
@@ -1412,6 +1424,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1412
1424
|
loadVideoHls,
|
|
1413
1425
|
loadVideoNative,
|
|
1414
1426
|
initialTime,
|
|
1427
|
+
shouldLoadMedia,
|
|
1415
1428
|
resetMediaForSourceChange,
|
|
1416
1429
|
reloadKey,
|
|
1417
1430
|
reloadToken,
|
|
@@ -1508,7 +1521,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1508
1521
|
crossOrigin,
|
|
1509
1522
|
playsInline: true,
|
|
1510
1523
|
muted,
|
|
1511
|
-
preload,
|
|
1524
|
+
preload: shouldLoadMedia ? preload : "none",
|
|
1512
1525
|
loop,
|
|
1513
1526
|
onPlay: () => setNextPlaying(true),
|
|
1514
1527
|
onPause: () => setNextPlaying(false),
|
package/dist/index.js
CHANGED
|
@@ -840,6 +840,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
840
840
|
const duration = durationProp != null ? durationProp : durationState;
|
|
841
841
|
const currentTime = currentTimeState;
|
|
842
842
|
const fullscreenAllowed = active != null ? active : true;
|
|
843
|
+
const shouldLoadMedia = active !== false;
|
|
843
844
|
const onTimeChangeRef = useRef2(onTimeChange);
|
|
844
845
|
const onDurationChangeRef = useRef2(onDurationChange);
|
|
845
846
|
onTimeChangeRef.current = onTimeChange;
|
|
@@ -1369,6 +1370,17 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1369
1370
|
liveStabilityMode.current = false;
|
|
1370
1371
|
liveStallEvents.current = [];
|
|
1371
1372
|
resetMediaForSourceChange();
|
|
1373
|
+
if (!shouldLoadMedia) {
|
|
1374
|
+
setTimeD.current.cancel();
|
|
1375
|
+
setCurrentTimeUi.current.cancel();
|
|
1376
|
+
setDurationState(0);
|
|
1377
|
+
setCurrentTimeState(0);
|
|
1378
|
+
setPlayingState(false);
|
|
1379
|
+
return () => {
|
|
1380
|
+
sourceLoadId.current += 1;
|
|
1381
|
+
resetMediaForSourceChange();
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1372
1384
|
if (sourceType === "native" || type === "video") loadVideoNative(loadId);
|
|
1373
1385
|
else if (sourceType === "hls") void loadVideo(initialTime, loadId);
|
|
1374
1386
|
else if (isLikelyHlsSource(videoSrc)) void loadVideoHls(loadId);
|
|
@@ -1383,6 +1395,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1383
1395
|
loadVideoHls,
|
|
1384
1396
|
loadVideoNative,
|
|
1385
1397
|
initialTime,
|
|
1398
|
+
shouldLoadMedia,
|
|
1386
1399
|
resetMediaForSourceChange,
|
|
1387
1400
|
reloadKey,
|
|
1388
1401
|
reloadToken,
|
|
@@ -1479,7 +1492,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1479
1492
|
crossOrigin,
|
|
1480
1493
|
playsInline: true,
|
|
1481
1494
|
muted,
|
|
1482
|
-
preload,
|
|
1495
|
+
preload: shouldLoadMedia ? preload : "none",
|
|
1483
1496
|
loop,
|
|
1484
1497
|
onPlay: () => setNextPlaying(true),
|
|
1485
1498
|
onPause: () => setNextPlaying(false),
|