-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperience.php
209 lines (184 loc) · 8.84 KB
/
experience.php
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
<?php
// Global database/session initialization.
require_once "./config.php";
require_once "./content/thumbnail.php";
require_once "./content/video.php";
// require_once "./content/download.php";
?>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="./styles.css">
<link rel="stylesheet" type="text/css" href="./player/video-js.css">
<link rel="stylesheet" type="text/css" href="./player/videojs-resolution-switcher.css">
<script src="./player/video.js"></script>
<script src="./assets/jquery-1.11.3.js"></script>
</head>
<body>
<div class="experienceContainer">
<article id="videoContainer">
<?php
$stmt = $pdo->prepare("SELECT date_time, thumb, vimeo_id, youtube_id, length, embed_code, thumb FROM archives WHERE id = :id");
$stmt->bindParam(":id", $param_id, PDO::PARAM_STR);
$param_id = trim($_GET["id"]);
$stmt->execute();
$result = $stmt->fetch();
?>
<?php getArchiveVideo($result['embed_code'], $result['vimeo_id'], $result['youtube_id']); ?>
<a class="button-orange" style="margin-right: 5px;" href="/archives.php">Back to List</a>
<a class="button-blue" style="margin-right: 5px;" href="https://twitter.com/intent/tweet?button_hashtag=<?php echo $hashtag ?>">Tweet #<?php echo $hashtag ?></a>
<a class="button-blue" <?php echo "href='./download.php?vimeo_id=" . $result['vimeo_id'] . "'";?>>Download</a>
<script>
function hideChat() {
document.getElementById("chatContainer").style.display = "none";
document.getElementById("chat-toggle").setAttribute("onclick", "showChat()");
document.getElementById("chat-toggle").innerHTML = "Show Chat";
}
function showChat() {
document.getElementById("chatContainer").style.display = "unset";
document.getElementById("chat-toggle").setAttribute("onclick", "hideChat()");
document.getElementById("chat-toggle").innerHTML = "Hide Chat";
}
</script>
<a id="chat-toggle" class="button-blue right-button" style="margin-left: 9px;" onclick="hideChat()">Hide Chat</a>
<?php
// If you're an admin, display an edit button.
if($_SESSION["admin"] == true){
echo "<a class=\"button-blue right-button\" href=\"/experience-edit.php?id=" . trim($_GET["id"]) . "\">Edit Episode</a>";
}elseif($_SESSION["id"] == ""){ // If you're not logged in, display a login button.
echo "<a class=\"button-blue right-button\" href=\"/login.php?id=" . trim($_GET["id"]) . "\">Log In</a>";
}
?>
<br/>
<h1 class="full-title"><?php echo $result['title']; ?></h1>
<?php $rawdate = strtotime($result["date_time"]);
$prettydate = date("l, d F Y @ g:i A", $rawdate); ?>
<p class="full-date"><?php echo $prettydate; ?></p>
<hr style="width: 50%; border: dashed; border-width: 1px;" />
<div class="experience-info">
<p class="primary-game"><span style="font-weight: bold;">Primary game:</span> <?php echo $result['primary_game']; ?>
<p class="secondary-game"><span style="font-weight: bold;">Secondary game:</span> <?php echo $result['secondary_game']; ?>
<p class="runtime"><span style="font-weight: bold;">Runtime:</span> <?php echo $result['length']; ?>
</div>
</article>
<article id="chatContainer">
<div id="display-cues-1" class="display-cues">
<p id="start-point-1"><p>
</div>
</article>
</div>
<?php require_once "./footer.php"; ?>
<script>
function matchHeight() {
var vidHeight = $("#content_video_html5_api").height();
document.getElementById("display-cues-1").style.height = vidHeight + "px";
console.log(vidHeight);
}
$(window).resize(function() {
matchHeight();
});
$(document).ready(function() {
console.log("Running chat setup!");
matchHeight();
// Create an object to manipulate the VideoJS player.
myPlayer = videojs('content_video');
var cuesTime = [];
var onHover = [];
jumpToTime = function (video_id, t){
myPlayer.currentTime(t + 0.01);
}
video_id = 1;
var track = document.getElementById("entrack-" + video_id); // get text track from track element
console.log(track);
// Wait until the WebVTT file has been downloaded.
function checkTracks() {
if (myPlayer.textTracks_.getTrackById("entrack-1") == null) {
console.log("Track is null, waiting 1 second...");
window.setTimeout(checkTracks, 1000);
} else {
if (myPlayer.textTracks_.getTrackById("entrack-1").cues == null) {
console.log("Chat is null, waiting 1 second...");
window.setTimeout(checkTracks, 1000);
} else {
if (myPlayer.textTracks_.getTrackById("entrack-1").cues < 1) {
console.log("Chat log is not loaded yet, waiting 1 second...");
window.setTimeout(checkTracks, 1000);
} else {
var cues = myPlayer.textTracks_.getTrackById("entrack-1").cues;
console.log("Number of chat messages: " + cues.length);
// get list of cues
for (var i = 0; i < cues.length; i++) {
// console.log("found a cue - " + i);
if(i == 0){
cuesTime[video_id] = [];
cuesTime[video_id][i] = 0;
$('#display-cues-'+video_id).append('<p onclick="jumpToTime(' + video_id + ', ' + cues[i].startTime + ')" data-start-time-video-' + video_id + '="0" class="cue-active" id=' + i + '>' + cues[i].text + '</p>');
}else{
cuesTime[video_id][i] = cues[i].startTime;
$('#display-cues-'+video_id).append('<p onclick="jumpToTime(' + video_id + ', ' + cues[i].startTime + ')" data-start-time-video-' + video_id + '="' + cues[i].startTime + '" class="cue-hidden" id=' + i + '>' + cues[i].text + '</p>');
}
}
onHover[video_id] = false;
$('#display-cues-'+video_id).scrollTop(0);
// track.mode = "hidden";
onTrackLoad = function(video_id) {
// console.log("The track is: " + track);
// console.log("The video is: " + video_id);
// console.log("Track cues: " + track.cues.length);
myPlayer.on("timeupdate", function(event) {
var video_id = "1";
// console.log("time changed");
var currentTime = myPlayer.currentTime();
// console.log(myPlayer.currentTime());
var cueTimeCurrent = 0;
for (var i = 0; i < cuesTime[video_id].length; i++) {
if((currentTime - cuesTime[video_id][i]) <= 0){
cueTimeCurrent = cuesTime[video_id][i-1];
break;
}
cueTimeCurrent = cuesTime[video_id][i];
}
if(currentTime == 0){
cueTimeCurrent = 0;
}
// When a cue passes, remove the "active" highlight.
$('#display-cues-' + video_id + ' .cue-active').removeClass('cue-active');
// When a cue becomes active, unhide it and set the "active" highlight.
$('[data-start-time-video-' + video_id + '="' + cueTimeCurrent + '"]').removeClass('cue-hidden');
$('[data-start-time-video-' + video_id + '="' + cueTimeCurrent + '"]').addClass('cue-active');
var offsetTop = $('[data-start-time-video-' + video_id + '="' + cueTimeCurrent + '"]').offset().top - $('#start-point-'+video_id).offset().top;
if(!onHover[video_id]){
// This is an attempt to make the chat window scroll so the last visible message is at the bottom... currently a litle broken, it might be easier to just modify the cue generator so there's never two "active" messages at the same time.
var scrollOffset = offsetTop - document.getElementById('display-cues-1').offsetHeight + (document.getElementsByClassName('cue-active')[document.getElementsByClassName('cue-active').length - 1].offsetHeight * 2) + document.getElementsByClassName('cue-active')[document.getElementsByClassName('cue-active').length - 1].style.marginBottom;
$('#display-cues-' + video_id).scrollTop(scrollOffset);
// console.log(scrollOffset);
}
//console.log(offsetTop);
});
myPlayer.on("seeking", function(event) {
console.log("Video playback jumped!");
// In the event of a jump, unhide all previous chat messages immediately (because we skipped over them.)
currentChatMessage = document.getElementsByClassName('cue-active')[0].id;
for (i = 0; i < currentChatMessage; i++) {
document.getElementById(i).classList.remove('cue-hidden');
}
});
$('.display-cues').hover(function(event){
var video_id = (this.id).substring(13);
onHover[video_id] = true;
}, function (){
var video_id = (this.id).substring(13);
onHover[video_id] = false;
})
}
onTrackLoad(1);
}
}
}
}
checkTracks();
})
</script>
</body>
</html>