-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelectrocution.html
149 lines (132 loc) · 4.3 KB
/
electrocution.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<title>Electrocution</title>
<style>
input {
border: 1px solid rgb(46, 189, 235);
border-radius: 3px;
font-size: 1em;
outline: none;
padding: .2em .4em;
width: 60px;
text-align: center;
}
</style>
</head>
<body>
<h1>
Makeymakey Electrocution Gallery
</h1>
<h2>
NEVER PLAY WITH ELECTRICITY WITHOUT AN ADULT!
</h2>
<div>
<a href='#' id='charge'>CLICK HERE TO CHARGE THE ELECTRODES!</a>
</div>
<div>
<video width="640" height="360" id="videoPlayer" controls="true">
</video>
</div>
<div id="videos-container">
<a href='#' id='playAll'>Play all</a>
</div>
<div>
Charge the electrodes, then press space to trigger recording (perhaps via a Makeymakey
attached to two big electrodes made from tin foil). <a href="https://www.youtube.com/watch?v=sGiMtxlfiUk">Demo video here</a>. This currently only works in Firefox, due to using the
latest Web APIs to capture video from the webcam.
</div>
<script>
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
console.log('getUserMedia supported.');
var constraints = { video: true, audio: true };
var videosContainer = document.getElementById('videos-container');
var index = 1;
var videoElement = document.getElementById('videoPlayer');
var soundEffect = new Audio("shock.mp3");
var chargeSoundEffect = new Audio("electricity.mp3");
var playAllElement = document.getElementById('playAll');
var chargeElement = document.getElementById('charge');
var charged = false;
var onSuccess = function(stream) {
var mediaRecorder = new MediaRecorder(stream);
var showLive = function() {
videoElement.src = URL.createObjectURL(stream);
videoElement.play();
videoElement.volume = 0;
};
showLive();
document.onkeydown = function (e) {
if (e.keyCode == 32 && mediaRecorder.state == 'inactive' && charged) {
charged = false;
showLive();
mediaRecorder.start();
console.log("recorder started");
setTimeout(stopRecording, 5000);
soundEffect.play();
}
};
chargeElement.onclick = function() {
document.body.style.background = 'red';
charged = true;
showLive();
chargeSoundEffect.play();
};
playAllElement.onclick = function() {
videoElement.volume = 1;
var videoNodeList = document.getElementsByClassName('electrocutionVideo');
var videoURLArray = [];
for (var i = 0; i < videoNodeList.length; i++) {
videoURLArray.push(videoNodeList[i].objectURL);
}
var thisURL = videoURLArray.pop();
videoElement.src = thisURL;
videoElement.play();
videoElement.onended = function() {
var thisURL = videoURLArray.pop();
if (thisURL) {
videoElement.src = thisURL;
videoElement.play();
} else {
videoElement.onended = null;
}
}
};
function stopRecording() {
mediaRecorder.stop();
document.body.style.background = 'white';
console.log("recorder stopped");
}
mediaRecorder.mimeType = 'video/webm';
mediaRecorder.videoWidth = 1280;
mediaRecorder.videoHeight = 720;
mediaRecorder.ondataavailable = function(e) {
var a = document.createElement('a');
a.className = 'electrocutionVideo';
a.innerHTML = 'Video ' + (index++);
var blob = new Blob([e.data], {type: 'video/webm'});
a.objectURL = URL.createObjectURL(blob);
a.href = 'javascript:videoElement.src = "'+a.objectURL+'"; videoElement.volume = 1; videoElement.play();';
videosContainer.appendChild(a);
var span = document.createElement('span');
span.innerHTML = ' ';
videosContainer.appendChild(span);
videoElement.src = a.objectURL;
videoElement.volume = 1;
videoElement.play();
}
};
var onError = function(err) {
console.log('The following error occured: ' + err);
}
navigator.getUserMedia(constraints, onSuccess, onError);
} else {
console.log('getUserMedia not supported on your browser!');
}
</script>
</body>
</html>