@geekapps/silo-elements-nextjs 0.3.18 → 0.3.19
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/dist/VideoPlayer.js +29 -14
- package/dist/VideoPlayer.js.map +1 -1
- package/dist/index.js +29 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/VideoPlayer.js
CHANGED
|
@@ -29,24 +29,36 @@ function deviceSupportsOpus() {
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
if (typeof window === "undefined") return true;
|
|
32
|
+
function deviceSupportsVideoCodec(codec) {
|
|
33
|
+
if (!codec || typeof window === "undefined") return true;
|
|
34
|
+
if (/^avc1/i.test(codec)) return true;
|
|
34
35
|
try {
|
|
35
36
|
if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported) {
|
|
36
|
-
return MediaSource.isTypeSupported(`video/mp4; codecs="${
|
|
37
|
+
return MediaSource.isTypeSupported(`video/mp4; codecs="${codec}"`);
|
|
37
38
|
}
|
|
38
39
|
return true;
|
|
39
40
|
} catch {
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
function deviceSupportsAudioCodec(codec) {
|
|
45
|
+
if (!codec || typeof window === "undefined") return true;
|
|
46
|
+
if (/^mp4a/i.test(codec)) return true;
|
|
47
|
+
if (/^opus/i.test(codec)) return deviceSupportsOpus();
|
|
48
|
+
try {
|
|
49
|
+
if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported) {
|
|
50
|
+
return MediaSource.isTypeSupported(`audio/mp4; codecs="${codec}"`);
|
|
51
|
+
}
|
|
52
|
+
const a = document.createElement("audio");
|
|
53
|
+
return a.canPlayType(`audio/mp4; codecs="${codec}"`) !== "";
|
|
54
|
+
} catch {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
43
58
|
function isHdrLevel(level) {
|
|
44
59
|
const range = level?.videoRange ?? level?.video_range ?? "";
|
|
45
60
|
return range === "PQ" || range === "HLG" || range === "HDR10" || typeof level?.name === "string" && /hdr/i.test(level.name);
|
|
46
61
|
}
|
|
47
|
-
function isHdrAudioCodec(codecStr) {
|
|
48
|
-
return /opus/i.test(codecStr);
|
|
49
|
-
}
|
|
50
62
|
var PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
51
63
|
function Source(_props) {
|
|
52
64
|
return null;
|
|
@@ -832,10 +844,14 @@ function Video({
|
|
|
832
844
|
AUTO_QUALITY,
|
|
833
845
|
...levels.map((level, index) => {
|
|
834
846
|
const hdr = isHdrLevel(level);
|
|
835
|
-
const
|
|
836
|
-
const
|
|
847
|
+
const rawCodecs = (level.attrs?.CODECS ?? "").split(",").map((c) => c.trim());
|
|
848
|
+
const videoCodec = level.videoCodec ?? rawCodecs.find((c) => /^avc1|^hvc1|^hev1|^av01|^vp09/i.test(c)) ?? rawCodecs[0] ?? "";
|
|
849
|
+
const audioCodec = level.audioCodec ?? rawCodecs.find((c) => /^mp4a|^opus|^ec-3|^ac-3/i.test(c)) ?? "";
|
|
850
|
+
const videoOk = deviceSupportsVideoCodec(videoCodec);
|
|
851
|
+
const audioOk = deviceSupportsAudioCodec(audioCodec);
|
|
852
|
+
const supported = (hdr ? hdrSupported : true) && videoOk && audioOk;
|
|
837
853
|
const baseName = level.name ?? (level.height ? `${level.height}p` : `${index + 1}`);
|
|
838
|
-
const label = hdr ? `${baseName} HDR` : baseName;
|
|
854
|
+
const label = hdr && hdrSupported ? `${baseName} HDR` : baseName;
|
|
839
855
|
return { id: `hls-${index}`, label, type: "hls", index, supported, hdr };
|
|
840
856
|
})
|
|
841
857
|
]);
|
|
@@ -844,8 +860,8 @@ function Video({
|
|
|
844
860
|
if (tracks.length > 1) {
|
|
845
861
|
setAudioTracks(
|
|
846
862
|
tracks.map((t, i) => {
|
|
847
|
-
const codec = t.attrs?.CODECS ?? t.codecSet ?? "";
|
|
848
|
-
const supported =
|
|
863
|
+
const codec = (t.attrs?.CODECS ?? t.codecSet ?? "").split(",")[0]?.trim() ?? "";
|
|
864
|
+
const supported = deviceSupportsAudioCodec(codec);
|
|
849
865
|
return { id: i, label: t.name ?? t.lang ?? `Track ${i + 1}`, supported };
|
|
850
866
|
})
|
|
851
867
|
);
|
|
@@ -858,12 +874,11 @@ function Video({
|
|
|
858
874
|
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
|
|
859
875
|
const tracks = data.audioTracks ?? [];
|
|
860
876
|
console.debug("[Silo/hls] AUDIO_TRACKS_UPDATED", tracks.length);
|
|
861
|
-
const opusSupported = deviceSupportsOpus();
|
|
862
877
|
if (tracks.length > 1) {
|
|
863
878
|
setAudioTracks(
|
|
864
879
|
tracks.map((t, i) => {
|
|
865
|
-
const codec = t.attrs?.CODECS ?? t.codecSet ?? "";
|
|
866
|
-
const supported =
|
|
880
|
+
const codec = (t.attrs?.CODECS ?? t.codecSet ?? "").split(",")[0]?.trim() ?? "";
|
|
881
|
+
const supported = deviceSupportsAudioCodec(codec);
|
|
867
882
|
return { id: i, label: t.name ?? t.lang ?? `Track ${i + 1}`, supported };
|
|
868
883
|
})
|
|
869
884
|
);
|