-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
68 lines (61 loc) · 2.38 KB
/
core.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//Option for camer and audio
let constraintObj ={
audio:false,
video:{
facingMode:'user',
width:{min:640,ideal:1280,max:1920},
height:{min:480,ideal:720,max:1080}
}
}
navigator.mediaDevices.getUserMedia(constraintObj)
//return audio and video information of user
.then(mediaStreamObj =>{
let liveCam = document.querySelector('#liveCam');
if('srcObject' in liveCam){
//Set video stream source to liveCam Video element
liveCam.srcObject = mediaStreamObj;
}else{
//Set video stream source to liveCam Video element in old browsers
liveCam.src = window.URL.createObjectURL(mediaStreamObj);
}
//Show in liveCam video element what captured from webcam
liveCam.onloadedmetadata = ev =>{liveCam.play()};
let StartReacording = document.querySelector('#StrRecordeing');
let StopReacording = document.querySelector('#StoRecordeing');
let SavedClipe = document.querySelector('#savedClipe');
//Add More Events
let recorderBot = new MediaRecorder(mediaStreamObj);
let chunks = [];
//Start Reacordeing
StartReacording.addEventListener('click',event =>{
recorderBot.start();
console.log(recorderBot.state);
SavedClipe.style.display = 'none';
liveCam.style.display = 'block';
let notec = document.createElement('p');
notec.textContent = "You are recordeing now !";
notec.id = "note";
document.querySelector('#options').appendChild(notec);
});
//Stop Reacordeing
StopReacording.addEventListener('click',event =>{
recorderBot.stop();
console.log(recorderBot.state);
SavedClipe.style.display = 'block';
liveCam.style.display = 'none';
document.querySelector('#note').remove();
});
recorderBot.ondataavailable = event =>{
chunks.push(event.data);
};
recorderBot.onstop = event =>{
let blob = new Blob(chunks,{'type':'video/mp4;'});
chunks = [];
let videoURL = window.URL.createObjectURL(blob);
SavedClipe.src = videoURL;
}
})
//If there any error show the name of it and message
.catch(error =>{
console.log(`${error.name} ${error.message}`);
})