Spaces:
Running
Running
Download record_button.js from gstaff/gradio-screen-recorder: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/gstaff/gradio-screen-recorder/resolve/main/record_button.js
- Command line
-
hf download hf://spaces/gstaff/gradio-screen-recorder/record_button.js
-
curl -L -o record_button.js https://huggingface.co/spaces/gstaff/gradio-screen-recorder/resolve/main/record_button.js
1.26 kB
| // Setup if needed and start recording. | |
| async () => { | |
| // Set up recording functions if not already initialized | |
| if (!window.startRecording) { | |
| let recorder_js = null; | |
| let main_js = null; | |
| } | |
| // Function to fetch and convert video blob to base64 using async/await without explicit Promise | |
| async function getVideoBlobAsBase64(objectURL) { | |
| const response = await fetch(objectURL); | |
| if (!response.ok) { | |
| throw new Error('Failed to fetch video blob.'); | |
| } | |
| const blob = await response.blob(); | |
| const reader = new FileReader(); | |
| reader.readAsDataURL(blob); | |
| return new Promise((resolve, reject) => { | |
| reader.onloadend = () => { | |
| if (reader.result) { | |
| resolve(reader.result.split(',')[1]); // Return the base64 string (without data URI prefix) | |
| } else { | |
| reject('Failed to convert blob to base64.'); | |
| } | |
| }; | |
| }); | |
| } | |
| if (window.currentState === "RECORDING") { | |
| await window.stopRecording(); | |
| const base64String = await getVideoBlobAsBase64(window.videoSource); | |
| return base64String; | |
| } else { | |
| window.startRecording(); | |
| return "Record"; | |
| } | |
| } | |