-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
60 lines (51 loc) · 1.67 KB
/
script.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
document.addEventListener("DOMContentLoaded", function() {
const videoId = getVideoIdFromUrl();
if (videoId) {
fetchVideoData(videoId);
}
});
function getVideoIdFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get("id");
}
function fetchVideoData(videoId) {
fetch("videos.json")
.then(response => response.json())
.then(data => {
const video = data.videos.find(v => v.id === videoId);
if (video) {
displayVideo(video);
} else {
console.error("Video not found");
}
})
.catch(error => console.error(error));
}
function displayVideo(video) {
const videoPlayer = videojs("videoPlayer", {
controls: true,
autoplay: false,
preload: "auto",
});
// Clear any previously loaded sources
videoPlayer.src([]);
// Add the video source dynamically
videoPlayer.src([
{
src: video.video_file,
type: video.mime_type,
},
]);
const videoTitle = document.getElementById("videoTitle");
const videoUploader = document.getElementById("videoUploader");
const videoUploadDate = document.getElementById("videoUploadDate");
const videoDescription = document.getElementById("videoDescription");
videoTitle.textContent = video.title;
videoUploader.textContent = "Uploaded by: " + video.uploader;
videoUploadDate.textContent = "Uploaded on: " + formatDateTime(video.upload_date);
videoDescription.textContent = video.description;
}
function formatDateTime(dateTime) {
const options = { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" };
return new Date(dateTime).toLocaleString(undefined, options);
}