mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix: robustify WebTorrent playback startup to prevent gray screen
Improves the playback startup sequence in `js/webtorrent.js` by explicitly listening for `loadeddata` in addition to `canplay` and checking `readyState` immediately after streaming starts. This ensures autoplay is triggered reliably even if the browser has already buffered enough data or if the `canplay` event logic is bypassed. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
8c436aa613
commit
687b419182
1 file changed
+20
-14
+20
-14
@@ -747,16 +747,19 @@ export class TorrentClient {
|
||||
this.log("Video error:", e.target.error);
|
||||
});
|
||||
|
||||
videoElement.addEventListener(
|
||||
"canplay",
|
||||
() => {
|
||||
this.attemptAutoplay(videoElement, "chrome");
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
const tryStart = () => {
|
||||
this.attemptAutoplay(videoElement, "chrome");
|
||||
};
|
||||
|
||||
videoElement.addEventListener("canplay", tryStart, { once: true });
|
||||
videoElement.addEventListener("loadeddata", tryStart, { once: true });
|
||||
|
||||
try {
|
||||
file.streamTo(videoElement);
|
||||
// If the video is already ready (e.g. from cache or fast load), try starting immediately
|
||||
if (videoElement.readyState >= 3) {
|
||||
tryStart();
|
||||
}
|
||||
this.currentTorrent = torrent;
|
||||
resolve(torrent);
|
||||
} catch (err) {
|
||||
@@ -786,16 +789,19 @@ export class TorrentClient {
|
||||
this.log("Video error (Firefox path):", e.target.error);
|
||||
});
|
||||
|
||||
videoElement.addEventListener(
|
||||
"canplay",
|
||||
() => {
|
||||
this.attemptAutoplay(videoElement, "firefox");
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
const tryStart = () => {
|
||||
this.attemptAutoplay(videoElement, "firefox");
|
||||
};
|
||||
|
||||
videoElement.addEventListener("canplay", tryStart, { once: true });
|
||||
videoElement.addEventListener("loadeddata", tryStart, { once: true });
|
||||
|
||||
try {
|
||||
file.streamTo(videoElement, { highWaterMark: 256 * 1024 });
|
||||
// If the video is already ready (e.g. from cache or fast load), try starting immediately
|
||||
if (videoElement.readyState >= 3) {
|
||||
tryStart();
|
||||
}
|
||||
this.currentTorrent = torrent;
|
||||
resolve(torrent);
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user