-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
45 lines (39 loc) · 1.73 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
document.addEventListener("DOMContentLoaded", function () {
const initButton = document.getElementById('init');
let mediaRecorder;
initButton.addEventListener('click', async () => {
if (initButton.value === "▶️ Start") {
// Iniciar la grabación
const media = await navigator.mediaDevices.getDisplayMedia({
video: {
width: { ideal: 3840, max: 3840 }, // Ancho ideal y máximo de 3840px (4K)
height: { ideal: 2160, max: 2160 }, // Altura ideal y máxima de 2160px (4K)
frameRate: { ideal: 60 } // Velocidad de cuadros ideal de 60fps
},
audio: true // Incluir captura de audio
});
mediaRecorder = new MediaRecorder(media, {
mimeType: 'video/webm;codecs=vp8,opus' // Utiliza el codec VP9 para obtener la mejor calidad
});
mediaRecorder.start();
const [video] = media.getVideoTracks();
video.addEventListener("ended", () => {
mediaRecorder.stop();
initButton.value = "▶️ Start";
});
mediaRecorder.addEventListener("dataavailable", (e) => {
const link = document.createElement("a");
link.href = URL.createObjectURL(e.data);
link.download = "captura.mp4";
link.click();
});
// Cambiar el valor del botón a "⏸ Detener"
initButton.value = "⏸ Stop";
} else {
// Detener la grabación
mediaRecorder.stop();
// Cambiar el valor del botón a "▶️ Iniciar"
initButton.value = "▶️ Start";
}
});
});