This commit is contained in:
Renan LE CARO 2025-04-20 10:58:26 +02:00
parent 70f3c2307a
commit 1ba55bf2a6
13 changed files with 122 additions and 114 deletions

View file

@ -1,5 +1,5 @@
import { gameCanvas } from "./render";
import { max_levels } from "./game_utils";
import { isInWebView, max_levels } from "./game_utils";
import { getAudioRecordingTrack } from "./sounds";
import { t } from "./i18n/i18n";
import { GameState } from "./types";
@ -12,7 +12,7 @@ let mediaRecorder: MediaRecorder | null,
recordCanvasCtx: CanvasRenderingContext2D;
export function recordOneFrame(gameState: GameState) {
if (!isOptionOn("record")) {
if (!isOptionOn("record") || isInWebView) {
return;
}
// if (!gameState.running) return;
@ -59,7 +59,7 @@ export function drawMainCanvasOnSmallCanvas(gameState: GameState) {
}
export function startRecordingGame(gameState: GameState) {
if (!isOptionOn("record")) {
if (!isOptionOn("record") || isInWebView) {
return;
}
if (mediaRecorder) return;
@ -124,11 +124,8 @@ export function startRecordingGame(gameState: GameState) {
const a = document.createElement("a");
a.download = captureFileName("webm");
a.target = "_blank";
if (window.location.href.endsWith("index.html?isInWebView=true")) {
a.href = await blobToBase64(blob);
} else {
a.href = video.src;
}
a.href = video.src;
a.textContent = t("settings.record_download", {
size: (blob.size / 1000000).toFixed(2),
@ -137,22 +134,6 @@ export function startRecordingGame(gameState: GameState) {
};
}
function blobToBase64(blob: Blob): Promise<string> {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function (e) {
console.error(e);
reject(new Error("Failed to readAsDataURL of the video "));
};
reader.readAsDataURL(blob);
});
}
export function pauseRecording() {
if (!isOptionOn("record")) {
return;