+16
-1
src/components/embeds/players/video-player.tsx
+16
-1
src/components/embeds/players/video-player.tsx
···
21
21
22
22
const [playing, setPlaying] = createSignal(false);
23
23
24
+
const bwEstimate = currentAccount?.preferences.ui.videoBwEstimate;
24
25
const hls = new Hls({
25
26
capLevelToPlayerSize: true,
26
-
startLevel: 1,
27
+
28
+
// the '-1' value makes a test request to estimate bandwidth and quality level
29
+
// before showing the first fragment
30
+
startLevel: bwEstimate === undefined ? -1 : Hls.DefaultConfig.startLevel,
31
+
27
32
xhrSetup(xhr, urlString) {
28
33
// We want to replace the URL here so it points directly to the CDN,
29
34
// and not the middleware service.
···
46
51
},
47
52
});
48
53
54
+
if (bwEstimate !== undefined) {
55
+
hls.bandwidthEstimate = bwEstimate;
56
+
}
57
+
49
58
onCleanup(() => hls.destroy());
50
59
51
60
hls.loadSource(embed.playlist);
···
60
69
if (!isMobile && currentAccount) {
61
70
node.volume = currentAccount.preferences.ui.mediaVolume;
62
71
}
72
+
73
+
hls.on(Hls.Events.FRAG_LOADED, () => {
74
+
if (currentAccount) {
75
+
currentAccount.preferences.ui.videoBwEstimate = hls.bandwidthEstimate;
76
+
}
77
+
});
63
78
64
79
hls.on(Hls.Events.LEVEL_LOADED, (_event, data) => {
65
80
const hasAudio = data.levelInfo.audioCodec !== undefined;
+2
src/lib/preferences/account.ts
+2
src/lib/preferences/account.ts