Screen Recorder Tool
Screen Recorder Tool
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(45deg, #ff9a9e, #fad0c4);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #fff;
}
.container {
text-align: center;
background: #ffffff10;
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
h1 {
font-size: 2em;
margin-bottom: 20px;
}
video {
width: 100%;
max-width: 600px;
height: auto;
border: 2px solid #fff;
border-radius: 10px;
margin-bottom: 20px;
}
.buttons {
display: flex;
justify-content: center;
gap: 10px;
}
button {
background: #4caf50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 1em;
cursor: pointer;
transition: background 0.3s ease;
}
button:disabled {
background: #bbb;
cursor: not-allowed;
}
button:hover:not(:disabled) {
background: #45a049;
}
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
const downloadBtn = document.getElementById('downloadBtn');
const preview = document.getElementById('preview');
let recorder;
let stream;
startBtn.addEventListener('click', async () => {
try {
// Request screen capture
stream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: true });
preview.srcObject = stream;
// Initialize RecordRTC
recorder = new RecordRTC(stream, { type: 'video' });
recorder.startRecording();
startBtn.disabled = true;
stopBtn.disabled = false;
} catch (err) {
alert('Error starting screen recording: ' + err.message);
}
});
stopBtn.addEventListener('click', () => {
recorder.stopRecording(() => {
const blob = recorder.getBlob();
// Allow downloading
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'screen-recording.webm';
downloadBtn.href = url;
downloadBtn.download = 'screen-recording.webm';
downloadBtn.disabled = false;
// Stop media stream
stream.getTracks().forEach(track => track.stop());
preview.srcObject = null;
});
startBtn.disabled = false;
stopBtn.disabled = true;
});
0 Comments