New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: video files not seekable with protocol.handle #38749
Comments
Hello @philer. Thanks for reporting this and helping to make Electron better! Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use. Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests. Now adding the |
@codebytere I don't think this is something I can reproduce in a fiddle… |
Hello! Electron: 25.1.0 Fiddle: This text was translated by Deepl. |
I see, thanks! 👍 |
protocol.handle("https", async (request) => {
const path = "G:/big_buck_bunny_trailer_480p_logo.webm";
const stats = await stat(path);
const headers = new Headers();
headers.set("Accept-Ranges", "bytes");
headers.set("Content-Type", "video/webm");
let status = 200;
const rangeText = request.headers.get("range");
let stream;
if (rangeText) {
const ranges = parseRangeRequests(rangeText, stats.size);
const [start, end] = ranges[0];
console.log(rangeText, stats.size, start, end);
headers.set("Content-Length", `${end - start + 1}`);
headers.set("Content-Range", `bytes ${start}-${end}/${stats.size}`);
status = 206;
stream = createReadStream(path, { start, end });
} else {
headers.set("Content-Length", `${stats.size}`);
stream = createReadStream(path);
}
return new Response(stream, {
headers,
status,
});
});
function parseRangeRequests(text, size) {
const token = text.split("=");
if (token.length !== 2 || token[0] !== "bytes") {
return [];
}
return token[1]
.split(",")
.map((v) => parseRange(v, size))
.filter(([start, end]) => !isNaN(start) && !isNaN(end) && start <= end);
}
const NAN_ARRAY = [NaN, NaN];
function parseRange(text, size) {
const token = text.split("-");
if (token.length !== 2) {
return NAN_ARRAY;
}
const startText = token[0].trim();
const endText = token[1].trim();
if (startText === "") {
if (endText === "") {
return NAN_ARRAY;
} else {
let start = size - Number(endText);
if (start < 0) {
start = 0;
}
return [start, size - 1];
}
} else {
if (endText === "") {
return [Number(startText), size - 1];
} else {
let end = Number(endText);
if (end >= size) {
end = size - 1;
}
return [Number(startText), end];
}
}
} |
Affects plain audio files, as well. Present on Mac and Windows (haven't tested Linux yet, but if someone wants, just ask) Workaround is staying on the deprecated API for the time being. |
@nornagon would you be able to take a look at this one? |
Still an issue. Also, similar as to this comment from 2021t, the issue only affects the first load of a video item. I.e. if we close and re-open the video, then suddenly seeking does work. |
Also having this issue. Currently |
Preflight Checklist
Electron Version
25.1.0
What operating system are you using?
Other Linux
Operating System Version
Linux Mint 21.1
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
I'm using a custom protocol in place of
file://
URLs for a video player. This works:Since
protocol.registerFileProtocol
got deprecated in version 25, I tried the suggested alternativeprotocol.handle
as per the update notes:This allows me to play videos. However now when I set
.currentTime
on a<video>
element with avideo://…
source, it just jumps back to zero.video.seekable.end()
is always0
. This breaks seeking in HTML5 videos with custom protocol URLs.I've also tried this, with the same result:
Not sure if it matters, the scheme is registered like this:
Expected behavior: The documented alternative to
protocol.registerFileProtocol
should allow serving seekable video files.Actual Behavior
See above.
Testcase Gist URL
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: