-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
217 lines (178 loc) · 5.28 KB
/
index.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<style>
.invisible {
opacity: 0;
}
.visible {
}
#audioHider {
opacity: 0;
position: absolute;
}
.button {
background-color: gray;
border: 1px solid black;
width: 640px;
}
#videoText, #audioText {
width: 400px;
margin-left: 10px;
}
body {
text-align: center;
}
@font-face {
font-family: 'HVDPosterRegular';
src: url('HVD_Poster-webfont.eot');
src: url('HVD_Poster-webfont.eot?#iefix') format('embedded-opentype'),
url('HVD_Poster-webfont.woff') format('woff'),
url('HVD_Poster-webfont.ttf') format('truetype'),
url('HVD_Poster-webfont.svg#HVDPosterRegular') format('svg');
font-weight: normal;
font-style: normal;
}
h1 {
font: 60px 'HVDPosterRegular';
text-transform: uppercase;
}
</style>
<div id="header"><h1>The Dubbler</h1></div>
<div id="content">
<div id="videoHider" class="invisible">
<div id="videoHolder">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
</div>
<div id="audioHider">
<div id="audioHolder"></div>
</div>
<button class="button" id="pause">Big ol' pause button</button>
<div id="inputs">
<div><label for="video">Video</label> <input id="videoText"></input></div>
<div><label for="audio">Audio</label> <input id="audioText"></input></div>
</div>
<div id="footer">OMG A FOOTER</div>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var data = window.location.hash.substr(1);
var config = data.split(":");
if (config.length == 2) {
videoText.value = "http://www.youtube.com/watch?v=" + config[0];
audioText.value = "http://www.youtube.com/watch?v=" + config[1];
}
var idRE = /v=([a-zA-Z0-9_-]+)/
function extractID(text) {
var result = idRE.exec(text);
if (result && result.length > 1) {
return result[1];
}
}
function updateVideos(event) {
if (event.keyCode == 13) {
var videoSource = extractID(videoText.value);
var audioSource = extractID(audioText.value);
config = [videoSource, audioSource];
console.log(config);
updateSources();
}
return true;
}
videoText.addEventListener("keypress", updateVideos);
audioText.addEventListener("keypress", updateVideos);
var params = { allowScriptAccess: "always" };
var atts = { id: "video" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=video&version=3", "videoHolder", "640", "480", "8", null, null, params, atts);
var atts = { id: "audio" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=audio&version=3", "audioHolder", "200", "200", "8", null, null, params, atts);
function YouTubeObject(playerId) {
this.playerId = playerId;
this.player = document.getElementById(playerId);
this.state = -1;
window["redirectorFor" + playerId] = function(event) { console.log(event, this); this.handleStateChange(event) }.bind(this);
this.player.addEventListener("onStateChange", "redirectorFor" + playerId);
this.stateChanged = undefined;
this.handleStateChange = function(event) {
if (this.stateChanged) {
this.stateChanged(event);
}
}
}
var video;
var audio;
var paused = false;
var pause = document.getElementById("pause");
function togglePause(event) {
if (paused) {
paused = false;
video.player.playVideo();
audio.player.playVideo();
} else {
paused = true;
video.player.pauseVideo();
audio.player.pauseVideo();
}
}
pause.addEventListener("click", togglePause);
document.addEventListener("keypress", function(event) {
if (event.charCode == 32) {
togglePause(event);
event.preventDefault();
return false;
}
return true;
});
function onYouTubePlayerReady(playerId) {
if (playerId == "video") {
video = new YouTubeObject("video");
} else {
audio = new YouTubeObject("audio");
}
if (video && audio) {
updateSources();
}
}
function updateSources() {
video.player.mute();
audio.player.mute();
video.stateChanged = waitForVideosToLoad;
video.player.stopVideo();
video.player.loadVideoById(config[0], 0, "default");
audio.stateChanged = waitForVideosToLoad;
audio.player.stopVideo();
audio.player.loadVideoById(config[1], 0, "hd720");
console.log("config is now ", config);
video.state = -1;
audio.state = -1;
document.getElementById("videoHider").setAttribute("class", "invisible");
}
var PLAYING = 1;
var PAUSED = 2;
var BUFFERING = 3;
var CUED = 5;
function waitForVideosToLoad(event) {
console.log("waitForVideosToLoad", event, this.playerId, video.state, audio.state);
if (event == PLAYING) {
this.state = event;
if (video.state == PLAYING && audio.state == PLAYING) {
setTimeout(playVideos, 0);
video.stateChanged = function(event) { handleBuffering.call(this, audio, event); };
audio.stateChanged = function(event) { handleBuffering.call(this, video, event); };
}
}
}
function handleBuffering(other, event) {
if (event == BUFFERING && other.state != BUFFERING) {
other.player.pauseVideo();
this.state = BUFFERING;
} else if (event == PLAYING && other.state != BUFFERING) {
other.player.playVideo();
this.state = PLAYING;
}
}
function playVideos() {
video.player.seekTo(0, true);
audio.player.seekTo(0, true);
audio.player.unMute();
document.getElementById("videoHider").setAttribute("class", "visible");
}
</script>