This commit is contained in:
2026-03-30 11:22:19 +02:00
parent db9201e2ed
commit d3197b9603
7 changed files with 57 additions and 7 deletions

View File

@@ -58,8 +58,8 @@ async function refreshPreviewFrame(): Promise<void> {
try {
const encoded = await invoke<string | null>("get_video_preview_frame_base64");
if (encoded !== null && encoded.length > 0 && videoPreview) {
videoPreview.src = `data:image/jpeg;base64,${encoded}`;
if (encoded !== null && encoded.length > 0) {
updatePreviewImageFromBase64(encoded);
}
} catch (error) {
console.error("preview refresh failed", error);
@@ -73,6 +73,12 @@ function startPreviewPolling(): void {
return;
}
console.log("starting preview polling");
window.setTimeout(() => {
void refreshPreviewFrame();
}, 120);
previewTimer = window.setInterval(() => {
void refreshPreviewFrame();
}, 200);
@@ -87,6 +93,11 @@ function stopPreviewPolling(): void {
previewRequestInFlight = false;
if (videoPreview)
videoPreview.removeAttribute("src");
if (previewObjectUrl !== null) {
URL.revokeObjectURL(previewObjectUrl);
previewObjectUrl = null;
}
}
startAudioBtn.addEventListener("click", async () => {
@@ -142,4 +153,35 @@ stopVideoBtn.addEventListener("click", async () => {
setVideoStatus(`Stop video failed.\n${String(error)}`);
setVideoButtons(true);
}
});
});
let previewObjectUrl: string | null = null;
function base64ToUint8Array(base64: string): Uint8Array {
const binary = window.atob(base64);
const bytes = new Uint8Array(binary.length);
for (let index = 0;index < binary.length;index += 1) {
bytes[index] = binary.charCodeAt(index);
}
return bytes;
}
function updatePreviewImageFromBase64(encoded: string): void {
const bytes = base64ToUint8Array(encoded);
const copied = new Uint8Array(bytes.byteLength);
copied.set(bytes);
const blob = new Blob([copied.buffer], { type: "image/jpeg" });
const objectUrl = URL.createObjectURL(blob);
if (previewObjectUrl !== null) {
URL.revokeObjectURL(previewObjectUrl);
}
previewObjectUrl = objectUrl;
if (videoPreview)
videoPreview.src = objectUrl;
}