Screen Recorder
Screen Recorder
css
Copy code
body {
font-family: Arial, sans-serif;
background-color: #f3f3f3;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
.controls {
text-align: center;
}
.recordButton {
padding: 10px 20px;
margin: 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.recordButton:hover {
background-color: #0056b3;
}
video {
display: block;
width: 100%;
margin-top: 20px;
}
javascript
Copy code
let recorder;
let stream;
const startButton = document.getElementById('startButton');
const stopButton = document.getElementById('stopButton');
const videoElement = document.getElementById('videoElement');
startButton.addEventListener('click', startRecording);
stopButton.addEventListener('click', stopRecording);
function startRecording() {
navigator.mediaDevices.getDisplayMedia({ video: true })
.then(function(s) {
stream = s;
videoElement.srcObject = stream;
recorder = new RecordRTC(stream, {
type: 'video',
mimeType: 'video/webm',
disableLogs: true
});
recorder.startRecording();
startButton.disabled = true;
stopButton.disabled = false;
})
.catch(function(err) {
console.error('Error accessing media devices.', err);
});
}
function stopRecording() {
recorder.stopRecording(function() {
stream.getTracks().forEach(track => track.stop());
videoElement.srcObject = null;
videoElement.src = URL.createObjectURL(recorder.getBlob());
videoElement.play();
startButton.disabled = false;
stopButton.disabled = true;
});
}