Spaces:
Running
Running
Update index.html
Browse files- index.html +721 -906
index.html
CHANGED
|
@@ -3,102 +3,297 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Video Library
|
| 7 |
-
<!-- Load Plyr.io -->
|
| 8 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.7.8/plyr.min.css" />
|
| 9 |
-
|
| 10 |
<style>
|
| 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 |
</style>
|
| 87 |
</head>
|
| 88 |
<body>
|
| 89 |
<div class="container">
|
| 90 |
<div class="header">
|
| 91 |
-
<h1>Video Library</h1>
|
| 92 |
</div>
|
| 93 |
-
|
| 94 |
<div class="search-container">
|
| 95 |
<input type="text" id="search" placeholder="Search videos...">
|
| 96 |
</div>
|
| 97 |
-
|
| 98 |
<div class="video-list">
|
| 99 |
<div class="video-grid" id="videoGrid">
|
| 100 |
-
<
|
| 101 |
-
|
|
|
|
| 102 |
</div>
|
| 103 |
<div class="pagination" id="pagination"></div>
|
| 104 |
</div>
|
|
@@ -107,954 +302,574 @@
|
|
| 107 |
<!-- Video Player Popup -->
|
| 108 |
<div class="popup-overlay" id="playerPopup">
|
| 109 |
<div class="popup-content">
|
| 110 |
-
<button class="close-popup" id="closePopup"
|
| 111 |
-
<div class="
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
<label for="qualitySelector">Quality:</label>
|
| 115 |
-
<select id="qualitySelector">
|
| 116 |
-
<option value="auto">Auto</option>
|
| 117 |
-
<!-- Quality options added dynamically -->
|
| 118 |
-
</select>
|
| 119 |
-
</div>
|
| 120 |
-
</div>
|
| 121 |
<div class="player-wrapper">
|
| 122 |
-
<div id="
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
<
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
</
|
| 129 |
-
<
|
| 130 |
-
|
| 131 |
-
</
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
</div>
|
| 136 |
</div>
|
| 137 |
</div>
|
| 138 |
|
| 139 |
-
<!-- Load required scripts -->
|
| 140 |
-
<script src="https://cdn.plyr.io/3.7.8/plyr.js"></script>
|
| 141 |
-
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script> <!-- DASH -->
|
| 142 |
-
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> <!-- HLS -->
|
| 143 |
-
|
| 144 |
<script>
|
| 145 |
-
//
|
| 146 |
let videoData = [];
|
| 147 |
let filteredVideos = [];
|
| 148 |
let currentVideo = null;
|
| 149 |
let currentPage = 1;
|
| 150 |
-
const videosPerPage =
|
| 151 |
-
let
|
| 152 |
-
let
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
let isDebugVisible = false;
|
| 156 |
-
|
| 157 |
-
// --- DOM Elements ---
|
| 158 |
const videoGrid = document.getElementById('videoGrid');
|
| 159 |
const pagination = document.getElementById('pagination');
|
| 160 |
const searchInput = document.getElementById('search');
|
| 161 |
const playerPopup = document.getElementById('playerPopup');
|
|
|
|
| 162 |
const currentTitle = document.getElementById('currentTitle');
|
| 163 |
const closePopup = document.getElementById('closePopup');
|
| 164 |
-
const
|
| 165 |
-
const
|
| 166 |
-
const
|
| 167 |
-
const
|
| 168 |
-
const
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
async function fetchVideoData() {
|
| 174 |
-
videoGrid.innerHTML = '<div class="video-thumbnail">Loading video index...</div>';
|
| 175 |
try {
|
| 176 |
-
|
| 177 |
-
const response = await fetch(`database.json?v=${Date.now()}`);
|
| 178 |
if (!response.ok) {
|
| 179 |
-
throw new Error(
|
| 180 |
}
|
| 181 |
const data = await response.json();
|
| 182 |
-
|
| 183 |
-
//
|
| 184 |
-
videoData = Array.isArray(data) ? data :
|
| 185 |
-
(data && Array.isArray(data.videos) ? data.videos : []);
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
console.warn("No videos found in database.json or format is incorrect.");
|
| 189 |
-
videoGrid.innerHTML = '<div class="no-videos">No videos found. Check database.json.</div>';
|
| 190 |
-
return;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
// Basic validation of video objects
|
| 194 |
-
videoData = videoData.filter(v => v && v.title && v.url);
|
| 195 |
-
|
| 196 |
-
// --- IMPORTANT: Add Thumbnail URLs ---
|
| 197 |
-
// You NEED to add 'thumbnailUrl' to your database.json entries
|
| 198 |
-
// Example: { "title": "My Video", "url": "path/to/manifest.m3u8", "thumbnailUrl": "path/to/thumbnail.jpg" }
|
| 199 |
videoData.forEach(video => {
|
| 200 |
-
if (
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
}
|
| 204 |
});
|
| 205 |
-
|
| 206 |
filteredVideos = [...videoData];
|
| 207 |
-
currentPage = 1; // Reset page on data load/refresh
|
| 208 |
renderPagination();
|
| 209 |
renderVideoGrid();
|
| 210 |
-
preloadThumbnailsForPage(currentPage);
|
| 211 |
-
|
| 212 |
} catch (error) {
|
| 213 |
-
console.error('Error fetching
|
| 214 |
videoGrid.innerHTML = `<div class="no-videos">Error loading videos: ${error.message}</div>`;
|
| 215 |
}
|
| 216 |
}
|
| 217 |
|
| 218 |
-
//
|
| 219 |
-
function preloadThumbnailsForPage(page) {
|
| 220 |
-
const startIndex = (page - 1) * videosPerPage;
|
| 221 |
-
const endIndex = Math.min(startIndex + videosPerPage, filteredVideos.length);
|
| 222 |
-
const videosOnPage = filteredVideos.slice(startIndex, endIndex);
|
| 223 |
-
|
| 224 |
-
videosOnPage.forEach(video => {
|
| 225 |
-
if (video.thumbnailUrl) {
|
| 226 |
-
const img = new Image();
|
| 227 |
-
img.src = video.thumbnailUrl;
|
| 228 |
-
}
|
| 229 |
-
});
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
// Render video grid for the current page
|
| 233 |
function renderVideoGrid() {
|
| 234 |
-
videoGrid.innerHTML = ''; // Clear previous items
|
| 235 |
if (filteredVideos.length === 0) {
|
| 236 |
-
videoGrid.innerHTML = '<div class="no-videos">No videos
|
|
|
|
| 237 |
return;
|
| 238 |
}
|
| 239 |
|
|
|
|
| 240 |
const startIndex = (currentPage - 1) * videosPerPage;
|
| 241 |
const endIndex = Math.min(startIndex + videosPerPage, filteredVideos.length);
|
|
|
|
| 242 |
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
return;
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
const fragment = document.createDocumentFragment();
|
| 249 |
-
for (let i = startIndex; i < endIndex; i++) {
|
| 250 |
-
const video = filteredVideos[i];
|
| 251 |
-
const videoItem = document.createElement('div');
|
| 252 |
-
videoItem.className = 'video-item';
|
| 253 |
-
videoItem.dataset.index = i; // Store the index in the filtered list
|
| 254 |
-
videoItem.innerHTML = `
|
| 255 |
<div class="video-thumbnail">
|
| 256 |
-
<img src="${video.thumbnailUrl || ''}" alt="${video.title}" loading="lazy" onerror="this.style.display='none'; this.parentElement.style.backgroundColor='#ccc';">
|
| 257 |
<div class="play-icon">▶</div>
|
| 258 |
</div>
|
| 259 |
<div class="video-item-title">${video.title}</div>
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
| 268 |
});
|
| 269 |
-
|
| 270 |
-
}
|
| 271 |
-
videoGrid.appendChild(fragment);
|
| 272 |
}
|
| 273 |
|
| 274 |
-
//
|
| 275 |
function renderPagination() {
|
| 276 |
-
pagination.innerHTML = ''; // Clear previous pagination
|
| 277 |
const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
endPage = totalPages;
|
| 287 |
} else {
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
if
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
} else if (currentPage + maxPagesAfterCurrent >= totalPages) {
|
| 295 |
-
startPage = totalPages - (maxVisibleButtons - 2);
|
| 296 |
-
endPage = totalPages;
|
| 297 |
-
} else {
|
| 298 |
-
startPage = currentPage - maxPagesBeforeCurrent;
|
| 299 |
-
endPage = currentPage + maxPagesAfterCurrent;
|
| 300 |
}
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
prevBtn.className = 'page-btn';
|
| 308 |
-
prevBtn.textContent = '‹';
|
| 309 |
-
prevBtn.disabled = currentPage === 1;
|
| 310 |
-
prevBtn.addEventListener('click', () => {
|
| 311 |
-
if (currentPage > 1) {
|
| 312 |
-
currentPage--;
|
| 313 |
-
renderPagination();
|
| 314 |
-
renderVideoGrid();
|
| 315 |
-
preloadThumbnailsForPage(currentPage);
|
| 316 |
-
window.scrollTo(0, videoGrid.offsetTop - 20);
|
| 317 |
}
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
if (startPage > 1) {
|
| 323 |
-
fragment.appendChild(createPageButton(1));
|
| 324 |
-
if (startPage > 2) {
|
| 325 |
-
const ellipsis = document.createElement('span');
|
| 326 |
-
ellipsis.className = 'page-btn';
|
| 327 |
-
ellipsis.textContent = '...';
|
| 328 |
-
ellipsis.style.cursor = 'default';
|
| 329 |
-
fragment.appendChild(ellipsis);
|
| 330 |
}
|
|
|
|
|
|
|
|
|
|
| 331 |
}
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
if (endPage < totalPages) {
|
| 338 |
-
if (endPage < totalPages - 1) {
|
| 339 |
-
const ellipsis = document.createElement('span');
|
| 340 |
-
ellipsis.className = 'page-btn';
|
| 341 |
-
ellipsis.textContent = '...';
|
| 342 |
-
ellipsis.style.cursor = 'default';
|
| 343 |
-
fragment.appendChild(ellipsis);
|
| 344 |
}
|
| 345 |
-
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
nextBtn.disabled = currentPage === totalPages;
|
| 353 |
-
nextBtn.addEventListener('click', () => {
|
| 354 |
-
if (currentPage < totalPages) {
|
| 355 |
-
currentPage++;
|
| 356 |
renderPagination();
|
| 357 |
renderVideoGrid();
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
}
|
| 361 |
-
});
|
| 362 |
-
fragment.appendChild(nextBtn);
|
| 363 |
-
|
| 364 |
-
pagination.appendChild(fragment);
|
| 365 |
-
}
|
| 366 |
-
|
| 367 |
-
// Helper to create a single pagination button
|
| 368 |
-
function createPageButton(pageNumber) {
|
| 369 |
-
const button = document.createElement('button');
|
| 370 |
-
button.className = 'page-btn';
|
| 371 |
-
button.textContent = pageNumber;
|
| 372 |
-
button.dataset.page = pageNumber;
|
| 373 |
-
if (pageNumber === currentPage) {
|
| 374 |
-
button.classList.add('active');
|
| 375 |
-
}
|
| 376 |
-
button.addEventListener('click', function() {
|
| 377 |
-
if (currentPage !== pageNumber) {
|
| 378 |
-
currentPage = pageNumber;
|
| 379 |
-
renderPagination(); // Re-render pagination to update active state
|
| 380 |
-
renderVideoGrid();
|
| 381 |
-
preloadThumbnailsForPage(currentPage);
|
| 382 |
-
window.scrollTo(0, videoGrid.offsetTop - 20); // Scroll towards top of grid
|
| 383 |
-
}
|
| 384 |
});
|
| 385 |
-
return button;
|
| 386 |
}
|
| 387 |
|
| 388 |
-
|
| 389 |
-
// --- Player Functions ---
|
| 390 |
-
|
| 391 |
-
// Clean up previous player instances (Plyr, HLS, DASH)
|
| 392 |
-
function cleanupPlayerInstances() {
|
| 393 |
-
console.log("Cleaning up player instances...");
|
| 394 |
-
if (debugInterval) {
|
| 395 |
-
clearInterval(debugInterval);
|
| 396 |
-
debugInterval = null;
|
| 397 |
-
}
|
| 398 |
-
if (player) {
|
| 399 |
-
try {
|
| 400 |
-
player.destroy();
|
| 401 |
-
} catch (e) { console.error("Error destroying Plyr:", e); }
|
| 402 |
-
player = null;
|
| 403 |
-
}
|
| 404 |
-
if (hls) {
|
| 405 |
-
try {
|
| 406 |
-
hls.stopLoad();
|
| 407 |
-
hls.detachMedia();
|
| 408 |
-
hls.destroy();
|
| 409 |
-
} catch (e) { console.error("Error destroying HLS:", e); }
|
| 410 |
-
hls = null;
|
| 411 |
-
}
|
| 412 |
-
if (dash) {
|
| 413 |
-
try {
|
| 414 |
-
dash.reset(); // Resets the MediaPlayer instance
|
| 415 |
-
} catch (e) { console.error("Error resetting DASH:", e); }
|
| 416 |
-
dash = null; // Assuming create() makes a new context
|
| 417 |
-
}
|
| 418 |
-
playerContainer.innerHTML = ''; // Clear the container
|
| 419 |
-
qualitySelector.innerHTML = '<option value="auto">Auto</option>'; // Reset quality
|
| 420 |
-
qualitySelector.value = 'auto';
|
| 421 |
-
qualitySelector.disabled = true;
|
| 422 |
-
debugOverlay.style.display = 'none';
|
| 423 |
-
isDebugVisible = false;
|
| 424 |
-
}
|
| 425 |
-
|
| 426 |
-
// Play the selected video
|
| 427 |
function playVideo(video) {
|
| 428 |
-
if (!video || !video.url) {
|
| 429 |
-
console.error("Invalid video object passed to playVideo:", video);
|
| 430 |
-
alert("Cannot play this video: Invalid data.");
|
| 431 |
-
return;
|
| 432 |
-
}
|
| 433 |
currentVideo = video;
|
| 434 |
-
currentTitle.textContent = video.title
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
initializeStreamingPlayer(videoElement, video.url);
|
| 451 |
-
}
|
| 452 |
-
|
| 453 |
-
// Initialize HLS.js, Dash.js, or standard HTML5 video based on URL
|
| 454 |
-
function initializeStreamingPlayer(videoElement, videoUrl) {
|
| 455 |
-
const url = videoUrl.trim();
|
| 456 |
-
const fileExtension = url.split('.').pop().toLowerCase().split('?')[0]; // Get extension before query params
|
| 457 |
-
|
| 458 |
-
console.log(`Initializing player for URL: ${url} (Extension: ${fileExtension})`);
|
| 459 |
-
|
| 460 |
-
// --- IMPORTANT URL CHECK ---
|
| 461 |
-
// Check if the URL is actually accessible and looks like a media file/manifest
|
| 462 |
-
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
| 463 |
-
console.error("Video URL does not start with http:// or https://:", url);
|
| 464 |
-
alert(`Error: Invalid video URL format provided: ${url}`);
|
| 465 |
-
playerLoading.style.display = 'none';
|
| 466 |
-
closePlayerPopup(); // Close the broken player
|
| 467 |
-
return;
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
// Check for Hugging Face direct links - they might need specific handling
|
| 471 |
-
// or might not support streaming manifests directly without extra steps.
|
| 472 |
-
if (url.includes('huggingface.co') && (fileExtension === 'mp4' || fileExtension === 'webm' || fileExtension === 'mov')) {
|
| 473 |
-
console.warn("Detected direct Hugging Face file URL. ABR streaming (HLS/DASH) requires a manifest (.m3u8/.mpd). Seeking performance might be limited.");
|
| 474 |
-
// Proceed with standard player, but inform the user about potential limitations.
|
| 475 |
-
}
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
// 1. Check for HLS (.m3u8)
|
| 479 |
-
if (fileExtension === 'm3u8') {
|
| 480 |
-
if (Hls.isSupported()) {
|
| 481 |
-
console.log("Using HLS.js");
|
| 482 |
-
hls = new Hls({
|
| 483 |
-
// Configuration focused on stability and seeking
|
| 484 |
-
// Start with auto quality
|
| 485 |
-
startLevel: -1,
|
| 486 |
-
// Buffer settings: Allow seeking back easily, manage forward buffer
|
| 487 |
-
maxBufferLength: 60, // Max seconds of buffer
|
| 488 |
-
maxMaxBufferLength: 120, // Max buffer size when seeking forward
|
| 489 |
-
backBufferLength: 90, // Keep 90s behind current time for seeking back
|
| 490 |
-
// ABR settings: More stable, less aggressive switching
|
| 491 |
-
abrEwmaDefaultEstimate: 500000, // Start estimate lower (500kbps)
|
| 492 |
-
abrBandWidthFactor: 0.8, // Be slightly conservative
|
| 493 |
-
abrBandWidthUpFactor: 0.6, // Don't jump up too eagerly
|
| 494 |
-
// Performance
|
| 495 |
-
enableWorker: true, // Use web workers if available
|
| 496 |
-
// Low Latency (might not be needed unless it's a live stream)
|
| 497 |
-
// lowLatencyMode: false,
|
| 498 |
-
// Seeking / Frag loading tweaks
|
| 499 |
-
fragLoadingMaxRetry: 4,
|
| 500 |
-
levelLoadingMaxRetry: 4,
|
| 501 |
-
manifestLoadingMaxRetry: 2,
|
| 502 |
-
fragLoadingTimeOut: 15000, // 15 seconds timeout for fragments
|
| 503 |
-
levelLoadingTimeOut: 10000,
|
| 504 |
-
manifestLoadingTimeOut: 10000,
|
| 505 |
-
});
|
| 506 |
-
|
| 507 |
-
hls.loadSource(url);
|
| 508 |
-
hls.attachMedia(videoElement);
|
| 509 |
-
|
| 510 |
-
hls.on(Hls.Events.MANIFEST_PARSED, (event, data) => {
|
| 511 |
-
console.log("HLS Manifest Parsed:", data.levels);
|
| 512 |
-
initPlyr(videoElement); // Init Plyr *after* manifest is ready
|
| 513 |
-
populateQualitySelector(hls.levels.map((l, i) => ({ height: l.height, index: i })), 'hls');
|
| 514 |
-
});
|
| 515 |
-
|
| 516 |
-
hls.on(Hls.Events.LEVEL_SWITCHED, (event, data) => {
|
| 517 |
-
console.log(`HLS Level Switched: ${data.level}`);
|
| 518 |
-
if (qualitySelector.value !== 'auto') {
|
| 519 |
-
// If user manually selected a quality, but ABR switched away
|
| 520 |
-
// (e.g., due to bandwidth), reflect the change back to Auto.
|
| 521 |
-
// Or keep it? Decide on UX. Let's reset to Auto for clarity.
|
| 522 |
-
// const currentLevel = hls.levels[data.level];
|
| 523 |
-
// if (qualitySelector.value != currentLevel.height) {
|
| 524 |
-
// console.log("ABR override manual selection, resetting selector to Auto");
|
| 525 |
-
// qualitySelector.value = 'auto';
|
| 526 |
-
// }
|
| 527 |
-
}
|
| 528 |
-
updateDebugInfo();
|
| 529 |
-
});
|
| 530 |
-
|
| 531 |
-
hls.on(Hls.Events.ERROR, (event, data) => {
|
| 532 |
-
console.error('HLS Error:', data);
|
| 533 |
-
handleStreamingError(data, 'HLS');
|
| 534 |
-
});
|
| 535 |
-
|
| 536 |
-
} else if (videoElement.canPlayType('application/vnd.apple.mpegurl')) {
|
| 537 |
-
console.log("Using native HLS support");
|
| 538 |
-
videoElement.src = url;
|
| 539 |
-
initPlyr(videoElement); // Init Plyr for native HLS
|
| 540 |
-
qualitySelector.disabled = true; // Native HLS often doesn't expose quality levels easily
|
| 541 |
-
videoElement.addEventListener('loadedmetadata', () => {
|
| 542 |
-
playerLoading.style.display = 'none';
|
| 543 |
-
});
|
| 544 |
-
} else {
|
| 545 |
-
console.error("HLS not supported by HLS.js or natively.");
|
| 546 |
-
alert("Cannot play this video format (HLS) in your browser.");
|
| 547 |
-
playerLoading.style.display = 'none';
|
| 548 |
}
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
else if (fileExtension === 'mpd') {
|
| 552 |
-
console.log("Using Dash.js");
|
| 553 |
-
try {
|
| 554 |
-
dash = dashjs.MediaPlayer().create();
|
| 555 |
-
// Config for stability and seeking
|
| 556 |
-
dash.updateSettings({
|
| 557 |
-
'streaming': {
|
| 558 |
-
'abr': {
|
| 559 |
-
// 'ABRStrategy': 'abrL2A', // Throughput based
|
| 560 |
-
'useDefaultABRRules': true,
|
| 561 |
-
'ABRStrategy': 'abrThroughput', // Often better for VOD seeking
|
| 562 |
-
'bandwidthSafetyFactor': 0.8,
|
| 563 |
-
'useDeadTimeLatency': false, // Good for VOD
|
| 564 |
-
},
|
| 565 |
-
'buffer': {
|
| 566 |
-
'stableBufferTime': 30, // Target buffer
|
| 567 |
-
'bufferTimeAtTopQuality': 45, // Allow more buffer at highest quality
|
| 568 |
-
'bufferTimeAtTopQualityLongForm': 60,
|
| 569 |
-
'longFormContentDurationThreshold': 600, // Content > 10 mins
|
| 570 |
-
'bufferToKeep': 20, // Keep less behind playhead than HLS default
|
| 571 |
-
'bufferPruningInterval': 15,
|
| 572 |
-
'fastSwitchEnabled': true, // Enable faster quality switching
|
| 573 |
-
},
|
| 574 |
-
'scheduling': {
|
| 575 |
-
'scheduleWhilePaused': true, // Keep buffering when paused
|
| 576 |
-
}
|
| 577 |
-
}
|
| 578 |
-
});
|
| 579 |
-
|
| 580 |
-
dash.initialize(videoElement, url, true); // Autoplay = true
|
| 581 |
-
|
| 582 |
-
dash.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, () => {
|
| 583 |
-
console.log("DASH Stream Initialized");
|
| 584 |
-
initPlyr(videoElement);
|
| 585 |
-
const qualities = dash.getBitrateInfoListFor('video');
|
| 586 |
-
console.log("DASH Qualities:", qualities);
|
| 587 |
-
populateQualitySelector(qualities.map(q => ({ height: q.height, index: q.qualityIndex })), 'dash');
|
| 588 |
-
});
|
| 589 |
-
|
| 590 |
-
dash.on(dashjs.MediaPlayer.events.QUALITY_CHANGE_RENDERED, (e) => {
|
| 591 |
-
console.log(`DASH Quality Changed: ${e.mediaType} to ${e.newQuality} (${dash.getBitrateInfoListFor(e.mediaType)[e.newQuality]?.height}p)`);
|
| 592 |
-
updateDebugInfo();
|
| 593 |
-
});
|
| 594 |
-
|
| 595 |
-
dash.on(dashjs.MediaPlayer.events.ERROR, (e) => {
|
| 596 |
-
console.error('DASH Error:', e.error.message, e);
|
| 597 |
-
handleStreamingError(e.error, 'DASH'); // Pass the error object itself
|
| 598 |
-
});
|
| 599 |
-
|
| 600 |
-
} catch (error) {
|
| 601 |
-
console.error("Failed to initialize Dash.js:", error);
|
| 602 |
-
alert(`Error initializing DASH player: ${error.message}`);
|
| 603 |
-
playerLoading.style.display = 'none';
|
| 604 |
-
// Optionally fallback to standard player if possible?
|
| 605 |
-
}
|
| 606 |
-
}
|
| 607 |
-
// 3. Fallback to standard HTML5 video (mp4, webm, etc.)
|
| 608 |
-
else {
|
| 609 |
-
console.log(`Using standard HTML5 video player for extension: ${fileExtension}`);
|
| 610 |
-
if (videoElement.canPlayType(`video/${fileExtension}`) || fileExtension === 'mp4' || fileExtension === 'webm' || fileExtension === 'ogv') {
|
| 611 |
-
videoElement.src = url;
|
| 612 |
-
initPlyr(videoElement); // Initialize Plyr directly
|
| 613 |
-
qualitySelector.disabled = true; // No quality options for standard video
|
| 614 |
-
// Use loadedmetadata event for standard video as 'ready' might fire too early
|
| 615 |
-
videoElement.addEventListener('loadedmetadata', () => {
|
| 616 |
-
playerLoading.style.display = 'none';
|
| 617 |
-
});
|
| 618 |
-
videoElement.addEventListener('error', (e) => {
|
| 619 |
-
console.error("HTML5 Video Error:", videoElement.error);
|
| 620 |
-
alert(`Error playing video: ${videoElement.error?.message || 'Unknown error'}`);
|
| 621 |
-
playerLoading.style.display = 'none';
|
| 622 |
-
});
|
| 623 |
-
} else {
|
| 624 |
-
console.error(`Unsupported video format: ${fileExtension}`);
|
| 625 |
-
alert(`Your browser does not support the video format: ${fileExtension}`);
|
| 626 |
-
playerLoading.style.display = 'none';
|
| 627 |
-
}
|
| 628 |
-
}
|
| 629 |
-
}
|
| 630 |
-
|
| 631 |
-
// Handle errors from HLS.js or Dash.js
|
| 632 |
-
function handleStreamingError(errorData, sourceType) {
|
| 633 |
-
let shouldClose = false;
|
| 634 |
-
let message = `A ${sourceType} error occurred.`;
|
| 635 |
-
|
| 636 |
-
if (sourceType === 'HLS') {
|
| 637 |
-
if (errorData.fatal) {
|
| 638 |
-
message += ` Fatal error: ${errorData.type} - ${errorData.details}`;
|
| 639 |
-
console.error(message);
|
| 640 |
-
switch (errorData.type) {
|
| 641 |
-
case Hls.ErrorTypes.NETWORK_ERROR:
|
| 642 |
-
console.warn("HLS Network Error. Attempting recovery...");
|
| 643 |
-
if (hls) hls.startLoad(); // Try to recover network errors
|
| 644 |
-
else shouldClose = true;
|
| 645 |
-
break;
|
| 646 |
-
case Hls.ErrorTypes.MEDIA_ERROR:
|
| 647 |
-
console.warn("HLS Media Error. Attempting recovery...");
|
| 648 |
-
if (hls) hls.recoverMediaError();
|
| 649 |
-
else shouldClose = true;
|
| 650 |
-
break;
|
| 651 |
-
default:
|
| 652 |
-
console.error("Unrecoverable HLS error.");
|
| 653 |
-
shouldClose = true; // Close on other fatal errors
|
| 654 |
-
break;
|
| 655 |
-
}
|
| 656 |
-
} else {
|
| 657 |
-
// Non-fatal errors, just log them
|
| 658 |
-
message += ` Non-fatal: ${errorData.type} - ${errorData.details}`;
|
| 659 |
-
console.warn(message);
|
| 660 |
}
|
| 661 |
-
} else if (sourceType === 'DASH') {
|
| 662 |
-
message = `DASH Error: ${errorData.code} - ${errorData.message}`;
|
| 663 |
-
console.error(message, errorData);
|
| 664 |
-
// Dash.js errors are often less recoverable by simple API calls
|
| 665 |
-
shouldClose = true; // Assume most DASH errors require closing player for now
|
| 666 |
}
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
} else {
|
| 672 |
-
|
| 673 |
-
playerLoading.innerHTML = `<div class="spinner"></div><span>Error occurred, trying to recover...</span>`;
|
| 674 |
-
playerLoading.style.display = 'flex';
|
| 675 |
-
// Hide after a few seconds if playback resumes
|
| 676 |
-
setTimeout(() => {
|
| 677 |
-
if(player && !player.paused) playerLoading.style.display = 'none';
|
| 678 |
-
}, 3000);
|
| 679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
}
|
| 681 |
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
}
|
| 702 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
|
| 704 |
-
|
| 705 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 710 |
}
|
| 711 |
}
|
| 712 |
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
}
|
| 719 |
-
|
|
|
|
|
|
|
| 720 |
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
default: 'auto', // Corresponds to our value
|
| 731 |
-
options: [], // We populate this via populateQualitySelector
|
| 732 |
-
forced: true, // Use our logic
|
| 733 |
-
onChange: (newQuality) => {
|
| 734 |
-
// This might be called by Plyr's internal settings menu if enabled
|
| 735 |
-
// Let's sync our selector if Plyr changes it
|
| 736 |
-
console.log("Plyr quality onChange triggered:", newQuality);
|
| 737 |
-
const selectedHeight = parseInt(newQuality); // Plyr usually passes height
|
| 738 |
-
let foundOption = false;
|
| 739 |
-
for(let option of qualitySelector.options) {
|
| 740 |
-
if (option.dataset.height == selectedHeight) {
|
| 741 |
-
qualitySelector.value = option.value;
|
| 742 |
-
foundOption = true;
|
| 743 |
-
break;
|
| 744 |
-
}
|
| 745 |
-
}
|
| 746 |
-
if (!foundOption && newQuality === 'auto') {
|
| 747 |
-
qualitySelector.value = 'auto';
|
| 748 |
-
}
|
| 749 |
-
// Trigger our own change handler
|
| 750 |
-
handleQualityChange();
|
| 751 |
-
},
|
| 752 |
-
},
|
| 753 |
-
speed: { selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 2] },
|
| 754 |
-
keyboard: { focused: true, global: true }, // Allow spacebar etc.
|
| 755 |
-
tooltips: { controls: true, seek: true },
|
| 756 |
-
seekTime: 10, // Seek interval
|
| 757 |
-
// Ensure autoplay works after user interaction
|
| 758 |
-
autoplay: true, // Attempt autoplay
|
| 759 |
-
// Volume persistence
|
| 760 |
-
storage: { enabled: true, key: 'plyr_volume' },
|
| 761 |
-
// Fix for aspect ratio issues sometimes
|
| 762 |
-
ratio: '16:9', // Or detect dynamically if needed
|
| 763 |
-
};
|
| 764 |
|
|
|
|
| 765 |
try {
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
playerLoading.style.display = 'none';
|
| 772 |
-
// Attempt to play, might be blocked by browser
|
| 773 |
-
player.play().catch(error => console.warn('Autoplay prevented:', error));
|
| 774 |
-
initDebugOverlay(); // Setup debug toggle listener
|
| 775 |
-
});
|
| 776 |
-
|
| 777 |
-
player.on('playing', event => {
|
| 778 |
-
playerLoading.style.display = 'none';
|
| 779 |
-
updateDebugInfo(); // Start updating debug info if visible
|
| 780 |
-
});
|
| 781 |
-
|
| 782 |
-
player.on('waiting', event => {
|
| 783 |
-
playerLoading.style.display = 'flex'; // Show loading on buffer stall
|
| 784 |
-
});
|
| 785 |
-
|
| 786 |
-
player.on('seeking', event => {
|
| 787 |
-
playerLoading.style.display = 'flex'; // Show loading immediately on seek start
|
| 788 |
-
});
|
| 789 |
-
|
| 790 |
-
player.on('seeked', event => {
|
| 791 |
-
// Hide loading quickly after seek *if* video is ready to play
|
| 792 |
-
// Check if paused - if seeking while paused, don't hide loading
|
| 793 |
-
if (!player.paused) {
|
| 794 |
-
playerLoading.style.display = 'none';
|
| 795 |
-
}
|
| 796 |
-
});
|
| 797 |
-
|
| 798 |
-
player.on('qualitychange', event => {
|
| 799 |
-
console.log("Plyr qualitychange event (internal):", event.detail.quality);
|
| 800 |
-
updateDebugInfo();
|
| 801 |
-
});
|
| 802 |
-
|
| 803 |
-
player.on('error', event => {
|
| 804 |
-
console.error("Plyr player error:", event.detail.error);
|
| 805 |
-
// Don't necessarily close popup on generic plyr error, let HLS/DASH handle stream errors
|
| 806 |
-
});
|
| 807 |
-
|
| 808 |
-
player.on('controlsshown', () => updateDebugInfo()); // Update when controls appear
|
| 809 |
-
|
| 810 |
-
|
| 811 |
} catch (error) {
|
| 812 |
-
console.error(
|
| 813 |
-
alert(`Error initializing video player UI: ${error.message}`);
|
| 814 |
-
playerLoading.style.display = 'none';
|
| 815 |
}
|
|
|
|
| 816 |
}
|
| 817 |
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
console.
|
| 830 |
-
|
| 831 |
-
}
|
| 832 |
-
if (dash) {
|
| 833 |
-
console.log("Setting DASH to Auto quality");
|
| 834 |
-
dash.updateSettings({ 'streaming': { 'abr': { 'initialBitrate': { 'video': -1 }, 'autoSwitchBitrate': { 'video': true } } } });
|
| 835 |
-
}
|
| 836 |
} else {
|
| 837 |
-
|
| 838 |
-
const qualityIndex = parseInt(selectedValue);
|
| 839 |
-
if (!isNaN(qualityIndex)) {
|
| 840 |
-
if (hls) {
|
| 841 |
-
console.log(`Setting HLS quality index: ${qualityIndex}`);
|
| 842 |
-
hls.currentLevel = qualityIndex;
|
| 843 |
-
}
|
| 844 |
-
if (dash) {
|
| 845 |
-
console.log(`Setting DASH quality index: ${qualityIndex}`);
|
| 846 |
-
dash.updateSettings({ 'streaming': { 'abr': { 'autoSwitchBitrate': { 'video': false } } } });
|
| 847 |
-
// Setting quality might need a slight delay after disabling ABR
|
| 848 |
-
setTimeout(() => dash.setQualityFor('video', qualityIndex, true), 50); // true = immediate switch
|
| 849 |
-
}
|
| 850 |
-
} else {
|
| 851 |
-
console.warn("Invalid quality index selected:", selectedValue);
|
| 852 |
-
}
|
| 853 |
}
|
| 854 |
-
updateDebugInfo(); // Update debug info after change
|
| 855 |
}
|
| 856 |
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
|
|
|
|
|
|
|
|
|
| 864 |
}
|
| 865 |
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
debugToggle.addEventListener('click', toggleDebugDisplay);
|
| 871 |
-
// Reset state
|
| 872 |
-
debugOverlay.style.display = 'none';
|
| 873 |
-
isDebugVisible = false;
|
| 874 |
-
if (debugInterval) clearInterval(debugInterval);
|
| 875 |
}
|
| 876 |
|
| 877 |
-
function
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
|
|
|
| 884 |
}
|
| 885 |
} else {
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
|
|
|
|
|
|
| 890 |
}
|
| 891 |
}
|
| 892 |
}
|
| 893 |
|
| 894 |
-
function
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
const video = player.media;
|
| 898 |
-
let info = `Player State: ${player.playing ? 'Playing' : (player.paused ? 'Paused' : 'Idle')}\n`;
|
| 899 |
-
info += `Resolution: ${video.videoWidth}x${video.videoHeight}\n`;
|
| 900 |
-
info += `Time: ${formatTime(video.currentTime)} / ${formatTime(video.duration)}\n`;
|
| 901 |
-
info += `Volume: ${Math.round(player.volume * 100)}% ${player.muted ? '(Muted)' : ''}\n`;
|
| 902 |
-
info += `Playback Rate: ${player.speed}x\n`;
|
| 903 |
-
info += `Buffered: ${getBufferedRanges(video)}\n`;
|
| 904 |
-
info += `Network State: ${getNetworkState(video.networkState)}\n`;
|
| 905 |
-
info += `Ready State: ${getReadyState(video.readyState)}\n`;
|
| 906 |
-
|
| 907 |
-
if (hls) {
|
| 908 |
-
info += "\n--- HLS.js Info ---\n";
|
| 909 |
-
const currentLevel = hls.levels[hls.currentLevel];
|
| 910 |
-
const autoLevel = hls.autoLevelEnabled;
|
| 911 |
-
info += `Mode: HLS.js ${autoLevel ? '(Auto)' : '(Manual)'}\n`;
|
| 912 |
-
if (currentLevel) {
|
| 913 |
-
info += `Current Level: ${hls.currentLevel} (${currentLevel.width}x${currentLevel.height} @ ${formatBitrate(currentLevel.bitrate)})\n`;
|
| 914 |
-
} else {
|
| 915 |
-
info += `Current Level: ${hls.currentLevel} (Auto/Initial)\n`;
|
| 916 |
-
}
|
| 917 |
-
info += `Target Level: ${hls.nextLevel} ${hls.nextAutoLevel ? '(Auto)' : ''}\n`;
|
| 918 |
-
info += `Load Level: ${hls.loadLevel}\n`;
|
| 919 |
-
info += `Buffer Length: ${hls.mainForwardBufferInfo.len?.toFixed(2) || '?'}s\n`;
|
| 920 |
-
info += `Live Latency: ${hls.liveSyncPosition?.toFixed(2) || 'N/A'}s\n`;
|
| 921 |
-
const stats = hls.stats;
|
| 922 |
-
if (stats) {
|
| 923 |
-
info += `Dropped Frames: ${stats.totalDroppedFrames || 0}\n`;
|
| 924 |
-
info += `BW Estimate: ${formatBitrate(stats.bwEstimate)}\n`;
|
| 925 |
-
}
|
| 926 |
-
}
|
| 927 |
-
|
| 928 |
-
if (dash) {
|
| 929 |
-
info += "\n--- Dash.js Info ---\n";
|
| 930 |
-
const streamInfo = dash.getActiveStream()?.getStreamInfo();
|
| 931 |
-
const videoQuality = dash.getQualityFor('video');
|
| 932 |
-
const isAuto = dash.getSettings()?.streaming?.abr?.autoSwitchBitrate?.video ?? true;
|
| 933 |
-
info += `Mode: Dash.js ${isAuto ? '(Auto)' : '(Manual)'}\n`;
|
| 934 |
-
if (streamInfo) {
|
| 935 |
-
info += `Stream ID: ${streamInfo.id}\n`;
|
| 936 |
-
info += `Duration: ${formatTime(streamInfo.duration)}\n`;
|
| 937 |
-
}
|
| 938 |
-
const bitrateList = dash.getBitrateInfoListFor('video');
|
| 939 |
-
if (bitrateList && bitrateList[videoQuality]) {
|
| 940 |
-
const currentQuality = bitrateList[videoQuality];
|
| 941 |
-
info += `Current Quality: ${videoQuality} (${currentQuality.width}x${currentQuality.height} @ ${formatBitrate(currentQuality.bitrate)})\n`;
|
| 942 |
-
} else {
|
| 943 |
-
info += `Current Quality: ${videoQuality} (Unknown)\n`;
|
| 944 |
-
}
|
| 945 |
-
info += `Buffer Length: ${dash.getBufferLength('video')?.toFixed(2) || '?'}s\n`;
|
| 946 |
-
const dashMetrics = dash.getMetricsFor('video');
|
| 947 |
-
if (dashMetrics?.DroppedFrames) {
|
| 948 |
-
info += `Dropped Frames: ${dashMetrics.DroppedFrames.framesDropped || 0}\n`;
|
| 949 |
-
}
|
| 950 |
-
if(dashMetrics?.BufferLevel) {
|
| 951 |
-
const bufferLevels = dashMetrics.BufferLevel;
|
| 952 |
-
if(bufferLevels.length > 0) {
|
| 953 |
-
info += `Buffer Level (Last): ${bufferLevels[bufferLevels.length - 1].level.toFixed(2)}s\n`;
|
| 954 |
-
}
|
| 955 |
-
}
|
| 956 |
-
if (dashMetrics?.RequestsQueue) {
|
| 957 |
-
info += `Request Queue: ${dashMetrics.RequestsQueue.requestsQueue?.length || 0}\n`;
|
| 958 |
-
}
|
| 959 |
-
}
|
| 960 |
-
|
| 961 |
-
debugOverlay.textContent = info;
|
| 962 |
-
}
|
| 963 |
-
|
| 964 |
-
// Helper to format time
|
| 965 |
-
function formatTime(seconds) {
|
| 966 |
-
if (isNaN(seconds) || seconds === Infinity) return '0:00 / ∞';
|
| 967 |
-
const date = new Date(0);
|
| 968 |
-
date.setSeconds(seconds);
|
| 969 |
-
return date.toISOString().substr(11, 8); // HH:MM:SS format
|
| 970 |
-
}
|
| 971 |
-
|
| 972 |
-
// Helper to format bitrate
|
| 973 |
-
function formatBitrate(bits) {
|
| 974 |
-
if (isNaN(bits) || bits === 0) return '0 bps';
|
| 975 |
-
if (bits < 1000) return `${bits} bps`;
|
| 976 |
-
if (bits < 1000000) return `${(bits / 1000).toFixed(1)} kbps`;
|
| 977 |
-
return `${(bits / 1000000).toFixed(2)} Mbps`;
|
| 978 |
-
}
|
| 979 |
-
|
| 980 |
-
// Helper for buffered ranges
|
| 981 |
-
function getBufferedRanges(video) {
|
| 982 |
-
try {
|
| 983 |
-
const buffered = video.buffered;
|
| 984 |
-
if (!buffered || buffered.length === 0) return '[]';
|
| 985 |
-
let ranges = '';
|
| 986 |
-
for (let i = 0; i < buffered.length; i++) {
|
| 987 |
-
ranges += `[${formatTime(buffered.start(i))} - ${formatTime(buffered.end(i))}] `;
|
| 988 |
-
}
|
| 989 |
-
return ranges.trim();
|
| 990 |
-
} catch (e) {
|
| 991 |
-
return '[Error accessing buffer]';
|
| 992 |
-
}
|
| 993 |
}
|
| 994 |
|
| 995 |
-
//
|
| 996 |
-
function
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
case 2: return 'NETWORK_LOADING';
|
| 1001 |
-
case 3: return 'NETWORK_NO_SOURCE';
|
| 1002 |
-
default: return 'UNKNOWN';
|
| 1003 |
}
|
|
|
|
|
|
|
|
|
|
| 1004 |
}
|
| 1005 |
-
// Helper for ready state
|
| 1006 |
-
function getReadyState(state) {
|
| 1007 |
-
switch (state) {
|
| 1008 |
-
case 0: return 'HAVE_NOTHING';
|
| 1009 |
-
case 1: return 'HAVE_METADATA';
|
| 1010 |
-
case 2: return 'HAVE_CURRENT_DATA';
|
| 1011 |
-
case 3: return 'HAVE_FUTURE_DATA';
|
| 1012 |
-
case 4: return 'HAVE_ENOUGH_DATA';
|
| 1013 |
-
default: return 'UNKNOWN';
|
| 1014 |
-
}
|
| 1015 |
-
}
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
// --- Event Listeners ---
|
| 1019 |
|
| 1020 |
// Search functionality
|
| 1021 |
searchInput.addEventListener('input', function() {
|
| 1022 |
-
const searchTerm = this.value.toLowerCase()
|
| 1023 |
-
filteredVideos = videoData.filter(video =>
|
| 1024 |
video.title.toLowerCase().includes(searchTerm)
|
| 1025 |
);
|
| 1026 |
currentPage = 1; // Reset to first page on search
|
| 1027 |
renderPagination();
|
| 1028 |
renderVideoGrid();
|
| 1029 |
-
preloadThumbnailsForPage(currentPage);
|
| 1030 |
});
|
| 1031 |
|
| 1032 |
-
// Close popup button
|
| 1033 |
closePopup.addEventListener('click', closePlayerPopup);
|
| 1034 |
|
| 1035 |
-
// Close popup
|
| 1036 |
-
|
| 1037 |
-
if (e.
|
| 1038 |
closePlayerPopup();
|
| 1039 |
}
|
| 1040 |
-
// Let Plyr handle other keyboard shortcuts like space, arrows etc.
|
| 1041 |
});
|
| 1042 |
|
| 1043 |
-
//
|
| 1044 |
-
|
| 1045 |
-
if (
|
| 1046 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1047 |
}
|
| 1048 |
});
|
| 1049 |
|
| 1050 |
-
//
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1056 |
|
|
|
|
|
|
|
| 1057 |
</script>
|
| 1058 |
-
|
| 1059 |
</body>
|
| 1060 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>HF Video Library</title>
|
|
|
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
background-color: #f5f5f5;
|
| 16 |
+
padding: 20px;
|
| 17 |
+
max-width: 1200px;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
}
|
| 20 |
+
.container {
|
| 21 |
+
display: flex;
|
| 22 |
+
flex-direction: column;
|
| 23 |
+
gap: 20px;
|
| 24 |
+
}
|
| 25 |
+
.header {
|
| 26 |
+
background-color: #333;
|
| 27 |
+
color: white;
|
| 28 |
+
padding: 20px;
|
| 29 |
+
border-radius: 8px;
|
| 30 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 31 |
+
}
|
| 32 |
+
.search-container {
|
| 33 |
+
padding: 15px;
|
| 34 |
+
background-color: white;
|
| 35 |
+
border-radius: 8px;
|
| 36 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
| 37 |
+
}
|
| 38 |
+
#search {
|
| 39 |
+
width: 100%;
|
| 40 |
+
padding: 10px;
|
| 41 |
+
border: 1px solid #ddd;
|
| 42 |
+
border-radius: 4px;
|
| 43 |
+
font-size: 16px;
|
| 44 |
+
}
|
| 45 |
+
.video-list {
|
| 46 |
+
background-color: white;
|
| 47 |
+
border-radius: 8px;
|
| 48 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
| 49 |
+
padding: 15px;
|
| 50 |
+
}
|
| 51 |
+
.video-grid {
|
| 52 |
+
display: grid;
|
| 53 |
+
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
| 54 |
+
gap: 15px;
|
| 55 |
+
}
|
| 56 |
+
.video-item {
|
| 57 |
+
padding: 15px;
|
| 58 |
+
border: 1px solid #eee;
|
| 59 |
+
border-radius: 8px;
|
| 60 |
+
cursor: pointer;
|
| 61 |
+
transition: all 0.2s;
|
| 62 |
+
background-color: white;
|
| 63 |
+
}
|
| 64 |
+
.video-item:hover {
|
| 65 |
+
transform: translateY(-5px);
|
| 66 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
| 67 |
+
}
|
| 68 |
+
.video-thumbnail {
|
| 69 |
+
width: 100%;
|
| 70 |
+
height: 156px;
|
| 71 |
+
background-color: #333;
|
| 72 |
+
border-radius: 4px;
|
| 73 |
+
display: flex;
|
| 74 |
+
align-items: center;
|
| 75 |
+
justify-content: center;
|
| 76 |
+
margin-bottom: 10px;
|
| 77 |
+
overflow: hidden;
|
| 78 |
+
position: relative;
|
| 79 |
+
}
|
| 80 |
+
.video-thumbnail img {
|
| 81 |
+
width: 100%;
|
| 82 |
+
height: 100%;
|
| 83 |
+
object-fit: cover;
|
| 84 |
+
}
|
| 85 |
+
.video-item-title {
|
| 86 |
+
font-weight: 500;
|
| 87 |
+
margin-top: 10px;
|
| 88 |
+
white-space: nowrap;
|
| 89 |
+
overflow: hidden;
|
| 90 |
+
text-overflow: ellipsis;
|
| 91 |
+
}
|
| 92 |
+
.pagination {
|
| 93 |
+
display: flex;
|
| 94 |
+
justify-content: center;
|
| 95 |
+
gap: 5px;
|
| 96 |
+
margin-top: 20px;
|
| 97 |
+
}
|
| 98 |
+
.page-btn {
|
| 99 |
+
padding: 8px 12px;
|
| 100 |
+
background-color: white;
|
| 101 |
+
border: 1px solid #ddd;
|
| 102 |
+
border-radius: 4px;
|
| 103 |
+
cursor: pointer;
|
| 104 |
+
transition: background-color 0.2s;
|
| 105 |
+
}
|
| 106 |
+
.page-btn:hover {
|
| 107 |
+
background-color: #f0f0f0;
|
| 108 |
+
}
|
| 109 |
+
.page-btn.active {
|
| 110 |
+
background-color: #333;
|
| 111 |
+
color: white;
|
| 112 |
+
border-color: #333;
|
| 113 |
+
}
|
| 114 |
+
.popup-overlay {
|
| 115 |
+
position: fixed;
|
| 116 |
+
top: 0;
|
| 117 |
+
left: 0;
|
| 118 |
+
width: 100%;
|
| 119 |
+
height: 100%;
|
| 120 |
+
background-color: rgba(0,0,0,0.8);
|
| 121 |
+
display: flex;
|
| 122 |
+
align-items: center;
|
| 123 |
+
justify-content: center;
|
| 124 |
+
z-index: 1000;
|
| 125 |
+
opacity: 0;
|
| 126 |
+
visibility: hidden;
|
| 127 |
+
transition: opacity 0.3s, visibility 0.3s;
|
| 128 |
+
}
|
| 129 |
+
.popup-overlay.active {
|
| 130 |
+
opacity: 1;
|
| 131 |
+
visibility: visible;
|
| 132 |
+
}
|
| 133 |
+
.popup-content {
|
| 134 |
+
width: 90%;
|
| 135 |
+
max-width: 1024px;
|
| 136 |
+
background-color: #222;
|
| 137 |
+
border-radius: 8px;
|
| 138 |
+
overflow: hidden;
|
| 139 |
+
position: relative;
|
| 140 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.5);
|
| 141 |
+
}
|
| 142 |
+
.close-popup {
|
| 143 |
+
position: absolute;
|
| 144 |
+
top: 10px;
|
| 145 |
+
right: 10px;
|
| 146 |
+
background-color: rgba(0,0,0,0.5);
|
| 147 |
+
color: white;
|
| 148 |
+
border: none;
|
| 149 |
+
width: 30px;
|
| 150 |
+
height: 30px;
|
| 151 |
+
border-radius: 50%;
|
| 152 |
+
display: flex;
|
| 153 |
+
align-items: center;
|
| 154 |
+
justify-content: center;
|
| 155 |
+
cursor: pointer;
|
| 156 |
+
z-index: 10;
|
| 157 |
+
font-size: 18px;
|
| 158 |
+
}
|
| 159 |
+
.player-wrapper {
|
| 160 |
+
position: relative;
|
| 161 |
+
width: 100%;
|
| 162 |
+
padding-top: 56.25%; /* 16:9 Aspect Ratio */
|
| 163 |
+
}
|
| 164 |
+
#videoPlayer {
|
| 165 |
+
position: absolute;
|
| 166 |
+
top: 0;
|
| 167 |
+
left: 0;
|
| 168 |
+
width: 100%;
|
| 169 |
+
height: 100%;
|
| 170 |
+
background-color: #000;
|
| 171 |
+
}
|
| 172 |
+
.popup-title {
|
| 173 |
+
color: white;
|
| 174 |
+
padding: 15px;
|
| 175 |
+
font-size: 1.2em;
|
| 176 |
+
background-color: #111;
|
| 177 |
+
}
|
| 178 |
+
.controls {
|
| 179 |
+
display: flex;
|
| 180 |
+
gap: 10px;
|
| 181 |
+
padding: 15px;
|
| 182 |
+
background-color: #111;
|
| 183 |
+
flex-wrap: wrap;
|
| 184 |
+
}
|
| 185 |
+
.btn {
|
| 186 |
+
padding: 8px 16px;
|
| 187 |
+
background-color: #333;
|
| 188 |
+
color: white;
|
| 189 |
+
border: none;
|
| 190 |
+
border-radius: 4px;
|
| 191 |
+
cursor: pointer;
|
| 192 |
+
transition: background-color 0.2s;
|
| 193 |
}
|
| 194 |
+
.btn:hover {
|
| 195 |
+
background-color: #555;
|
| 196 |
+
}
|
| 197 |
+
.btn.active {
|
| 198 |
+
background-color: #007bff;
|
| 199 |
+
}
|
| 200 |
+
.instructions {
|
| 201 |
+
color: #ccc;
|
| 202 |
+
padding: 10px 15px;
|
| 203 |
+
background-color: #111;
|
| 204 |
+
font-size: 0.9em;
|
| 205 |
+
}
|
| 206 |
+
.play-icon {
|
| 207 |
+
font-size: 50px;
|
| 208 |
+
color: white;
|
| 209 |
+
opacity: 0.8;
|
| 210 |
+
transition: opacity 0.2s;
|
| 211 |
+
position: absolute;
|
| 212 |
+
}
|
| 213 |
+
.video-item:hover .play-icon {
|
| 214 |
+
opacity: 1;
|
| 215 |
+
}
|
| 216 |
+
.loading-spinner {
|
| 217 |
+
position: absolute;
|
| 218 |
+
top: 50%;
|
| 219 |
+
left: 50%;
|
| 220 |
+
transform: translate(-50%, -50%);
|
| 221 |
+
width: 40px;
|
| 222 |
+
height: 40px;
|
| 223 |
+
border: 4px solid rgba(255, 255, 255, 0.3);
|
| 224 |
+
border-radius: 50%;
|
| 225 |
+
border-top: 4px solid #fff;
|
| 226 |
+
animation: spin 1s linear infinite;
|
| 227 |
+
z-index: 10;
|
| 228 |
+
display: none;
|
| 229 |
+
}
|
| 230 |
+
@keyframes spin {
|
| 231 |
+
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
| 232 |
+
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
| 233 |
+
}
|
| 234 |
+
.buffering-indicator {
|
| 235 |
+
position: absolute;
|
| 236 |
+
bottom: 60px;
|
| 237 |
+
left: 10px;
|
| 238 |
+
background-color: rgba(0,0,0,0.5);
|
| 239 |
+
color: white;
|
| 240 |
+
padding: 5px 10px;
|
| 241 |
+
border-radius: 4px;
|
| 242 |
+
font-size: 12px;
|
| 243 |
+
z-index: 10;
|
| 244 |
+
display: none;
|
| 245 |
+
}
|
| 246 |
+
.seek-preview {
|
| 247 |
+
position: absolute;
|
| 248 |
+
bottom: 100px;
|
| 249 |
+
left: 50%;
|
| 250 |
+
transform: translateX(-50%);
|
| 251 |
+
background-color: rgba(0,0,0,0.7);
|
| 252 |
+
color: white;
|
| 253 |
+
padding: 5px 10px;
|
| 254 |
+
border-radius: 4px;
|
| 255 |
+
font-size: 14px;
|
| 256 |
+
z-index: 10;
|
| 257 |
+
display: none;
|
| 258 |
+
}
|
| 259 |
+
.no-videos {
|
| 260 |
+
padding: 20px;
|
| 261 |
+
text-align: center;
|
| 262 |
+
color: #777;
|
| 263 |
+
}
|
| 264 |
+
@media (max-width: 768px) {
|
| 265 |
+
.video-grid {
|
| 266 |
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
| 267 |
+
}
|
| 268 |
+
.popup-content {
|
| 269 |
+
width: 95%;
|
| 270 |
+
}
|
| 271 |
+
.controls {
|
| 272 |
+
gap: 5px;
|
| 273 |
+
padding: 10px;
|
| 274 |
+
}
|
| 275 |
+
.btn {
|
| 276 |
+
padding: 6px 12px;
|
| 277 |
+
font-size: 0.9em;
|
| 278 |
+
}
|
| 279 |
}
|
| 280 |
</style>
|
| 281 |
</head>
|
| 282 |
<body>
|
| 283 |
<div class="container">
|
| 284 |
<div class="header">
|
| 285 |
+
<h1>HF Video Library</h1>
|
| 286 |
</div>
|
| 287 |
+
|
| 288 |
<div class="search-container">
|
| 289 |
<input type="text" id="search" placeholder="Search videos...">
|
| 290 |
</div>
|
| 291 |
+
|
| 292 |
<div class="video-list">
|
| 293 |
<div class="video-grid" id="videoGrid">
|
| 294 |
+
<div class="video-item">
|
| 295 |
+
<div class="video-thumbnail">Loading...</div>
|
| 296 |
+
</div>
|
| 297 |
</div>
|
| 298 |
<div class="pagination" id="pagination"></div>
|
| 299 |
</div>
|
|
|
|
| 302 |
<!-- Video Player Popup -->
|
| 303 |
<div class="popup-overlay" id="playerPopup">
|
| 304 |
<div class="popup-content">
|
| 305 |
+
<button class="close-popup" id="closePopup">✕</button>
|
| 306 |
+
<div class="buffering-indicator" id="bufferingIndicator">Buffering...</div>
|
| 307 |
+
<div class="seek-preview" id="seekPreview"></div>
|
| 308 |
+
<div class="popup-title" id="currentTitle">Video Title</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
<div class="player-wrapper">
|
| 310 |
+
<div class="loading-spinner" id="loadingSpinner"></div>
|
| 311 |
+
<video id="videoPlayer" preload="auto" playsinline>
|
| 312 |
+
Your browser does not support the video tag.
|
| 313 |
+
</video>
|
| 314 |
+
</div>
|
| 315 |
+
<div class="controls">
|
| 316 |
+
<button class="btn" id="backwardBtn">⏪ 10s</button>
|
| 317 |
+
<button class="btn" id="playPauseBtn">⏯️ Play/Pause</button>
|
| 318 |
+
<button class="btn" id="forwardBtn">⏩ 10s</button>
|
| 319 |
+
<button class="btn" id="fullscreenBtn">⛶ Fullscreen</button>
|
| 320 |
+
<button class="btn" id="muteBtn">🔊 Mute/Unmute</button>
|
| 321 |
+
</div>
|
| 322 |
+
<div class="instructions">
|
| 323 |
+
<p><strong>Keyboard Controls:</strong> Space (Play/Pause) • ← (Back 10s) • → (Forward 10s) • F (Fullscreen) • M (Mute/Unmute)</p>
|
| 324 |
+
<p><strong>Double-tap:</strong> Left side (Back 10s) • Center (Play/Pause) • Right side (Forward 10s)</p>
|
| 325 |
</div>
|
| 326 |
</div>
|
| 327 |
</div>
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
<script>
|
| 330 |
+
// Global variables
|
| 331 |
let videoData = [];
|
| 332 |
let filteredVideos = [];
|
| 333 |
let currentVideo = null;
|
| 334 |
let currentPage = 1;
|
| 335 |
+
const videosPerPage = 10;
|
| 336 |
+
let isSeeking = false;
|
| 337 |
+
let preloadedSegments = new Set();
|
| 338 |
+
|
| 339 |
+
// DOM Elements
|
|
|
|
|
|
|
|
|
|
| 340 |
const videoGrid = document.getElementById('videoGrid');
|
| 341 |
const pagination = document.getElementById('pagination');
|
| 342 |
const searchInput = document.getElementById('search');
|
| 343 |
const playerPopup = document.getElementById('playerPopup');
|
| 344 |
+
const videoPlayer = document.getElementById('videoPlayer');
|
| 345 |
const currentTitle = document.getElementById('currentTitle');
|
| 346 |
const closePopup = document.getElementById('closePopup');
|
| 347 |
+
const playPauseBtn = document.getElementById('playPauseBtn');
|
| 348 |
+
const backwardBtn = document.getElementById('backwardBtn');
|
| 349 |
+
const forwardBtn = document.getElementById('forwardBtn');
|
| 350 |
+
const fullscreenBtn = document.getElementById('fullscreenBtn');
|
| 351 |
+
const muteBtn = document.getElementById('muteBtn');
|
| 352 |
+
const loadingSpinner = document.getElementById('loadingSpinner');
|
| 353 |
+
const bufferingIndicator = document.getElementById('bufferingIndicator');
|
| 354 |
+
const seekPreview = document.getElementById('seekPreview');
|
| 355 |
+
|
| 356 |
+
// Function to fetch video data
|
| 357 |
async function fetchVideoData() {
|
|
|
|
| 358 |
try {
|
| 359 |
+
const response = await fetch('database.json');
|
|
|
|
| 360 |
if (!response.ok) {
|
| 361 |
+
throw new Error('Failed to fetch video data');
|
| 362 |
}
|
| 363 |
const data = await response.json();
|
| 364 |
+
|
| 365 |
+
// Check if data has videos array or is itself an array
|
| 366 |
+
videoData = Array.isArray(data) ? data :
|
| 367 |
+
(data.videos && Array.isArray(data.videos) ? data.videos : []);
|
| 368 |
+
|
| 369 |
+
// Optimize HF URLs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
videoData.forEach(video => {
|
| 371 |
+
if (video.url.includes('huggingface.co')) {
|
| 372 |
+
// Force no-transform for HF URLs
|
| 373 |
+
if (!video.url.includes('?')) {
|
| 374 |
+
video.url += '?';
|
| 375 |
+
}
|
| 376 |
+
if (!video.url.includes('download=true')) {
|
| 377 |
+
video.url += (video.url.endsWith('?') ? '' : '&') + 'download=true';
|
| 378 |
+
}
|
| 379 |
}
|
| 380 |
});
|
| 381 |
+
|
| 382 |
filteredVideos = [...videoData];
|
|
|
|
| 383 |
renderPagination();
|
| 384 |
renderVideoGrid();
|
|
|
|
|
|
|
| 385 |
} catch (error) {
|
| 386 |
+
console.error('Error fetching video data:', error);
|
| 387 |
videoGrid.innerHTML = `<div class="no-videos">Error loading videos: ${error.message}</div>`;
|
| 388 |
}
|
| 389 |
}
|
| 390 |
|
| 391 |
+
// Function to render video grid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
function renderVideoGrid() {
|
|
|
|
| 393 |
if (filteredVideos.length === 0) {
|
| 394 |
+
videoGrid.innerHTML = '<div class="no-videos">No videos found</div>';
|
| 395 |
+
pagination.innerHTML = '';
|
| 396 |
return;
|
| 397 |
}
|
| 398 |
|
| 399 |
+
// Calculate start and end index for current page
|
| 400 |
const startIndex = (currentPage - 1) * videosPerPage;
|
| 401 |
const endIndex = Math.min(startIndex + videosPerPage, filteredVideos.length);
|
| 402 |
+
const currentVideos = filteredVideos.slice(startIndex, endIndex);
|
| 403 |
|
| 404 |
+
videoGrid.innerHTML = currentVideos.map((video, index) => `
|
| 405 |
+
<div class="video-item" data-index="${startIndex + index}">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
<div class="video-thumbnail">
|
|
|
|
| 407 |
<div class="play-icon">▶</div>
|
| 408 |
</div>
|
| 409 |
<div class="video-item-title">${video.title}</div>
|
| 410 |
+
</div>
|
| 411 |
+
`).join('');
|
| 412 |
+
|
| 413 |
+
// Add click event listeners to video items
|
| 414 |
+
document.querySelectorAll('.video-item').forEach(item => {
|
| 415 |
+
item.addEventListener('click', function() {
|
| 416 |
+
const index = parseInt(this.getAttribute('data-index'));
|
| 417 |
+
if (!isNaN(index) && index >= 0 && index < filteredVideos.length) {
|
| 418 |
+
playVideo(filteredVideos[index]);
|
| 419 |
+
}
|
| 420 |
});
|
| 421 |
+
});
|
|
|
|
|
|
|
| 422 |
}
|
| 423 |
|
| 424 |
+
// Function to render pagination
|
| 425 |
function renderPagination() {
|
|
|
|
| 426 |
const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
|
| 427 |
+
|
| 428 |
+
if (totalPages <= 1) {
|
| 429 |
+
pagination.innerHTML = '';
|
| 430 |
+
return;
|
| 431 |
+
}
|
| 432 |
|
| 433 |
+
// Determine which page buttons to show
|
| 434 |
+
let buttons = [];
|
| 435 |
+
if (totalPages <= 7) {
|
| 436 |
+
// Show all pages if 7 or fewer
|
| 437 |
+
for (let i = 1; i <= totalPages; i++) {
|
| 438 |
+
buttons.push(i);
|
| 439 |
+
}
|
|
|
|
| 440 |
} else {
|
| 441 |
+
// Always include first page
|
| 442 |
+
buttons.push(1);
|
| 443 |
+
|
| 444 |
+
// Add ellipsis if current page is more than 3
|
| 445 |
+
if (currentPage > 3) {
|
| 446 |
+
buttons.push('...');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
}
|
| 448 |
+
|
| 449 |
+
// Add pages around current page
|
| 450 |
+
const startPage = Math.max(2, currentPage - 1);
|
| 451 |
+
const endPage = Math.min(totalPages - 1, currentPage + 1);
|
| 452 |
+
for (let i = startPage; i <= endPage; i++) {
|
| 453 |
+
buttons.push(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
}
|
| 455 |
+
|
| 456 |
+
// Add ellipsis if current page is less than totalPages - 2
|
| 457 |
+
if (currentPage < totalPages - 2) {
|
| 458 |
+
buttons.push('...');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
}
|
| 460 |
+
|
| 461 |
+
// Always include last page
|
| 462 |
+
buttons.push(totalPages);
|
| 463 |
}
|
| 464 |
+
|
| 465 |
+
// Create pagination HTML
|
| 466 |
+
pagination.innerHTML = buttons.map(button => {
|
| 467 |
+
if (button === '...') {
|
| 468 |
+
return '<span class="page-btn">...</span>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
}
|
| 470 |
+
return `<button class="page-btn ${button === currentPage ? 'active' : ''}" data-page="${button}">${button}</button>`;
|
| 471 |
+
}).join('');
|
| 472 |
+
|
| 473 |
+
// Add click event listeners to page buttons
|
| 474 |
+
document.querySelectorAll('.page-btn[data-page]').forEach(button => {
|
| 475 |
+
button.addEventListener('click', function() {
|
| 476 |
+
currentPage = parseInt(this.getAttribute('data-page'));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
renderPagination();
|
| 478 |
renderVideoGrid();
|
| 479 |
+
window.scrollTo(0, 0);
|
| 480 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
});
|
|
|
|
| 482 |
}
|
| 483 |
|
| 484 |
+
// Function to play video with ultra-fast seeking
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
function playVideo(video) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
currentVideo = video;
|
| 487 |
+
currentTitle.textContent = video.title;
|
| 488 |
+
|
| 489 |
+
// Reset state
|
| 490 |
+
isSeeking = false;
|
| 491 |
+
preloadedSegments.clear();
|
| 492 |
+
|
| 493 |
+
// Show loading spinner
|
| 494 |
+
loadingSpinner.style.display = 'block';
|
| 495 |
+
bufferingIndicator.style.display = 'none';
|
| 496 |
+
|
| 497 |
+
// Optimize HF URL
|
| 498 |
+
let videoUrl = video.url;
|
| 499 |
+
if (videoUrl.includes('huggingface.co')) {
|
| 500 |
+
if (!videoUrl.includes('?')) {
|
| 501 |
+
videoUrl += '?';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
}
|
| 503 |
+
if (!videoUrl.includes('download=true')) {
|
| 504 |
+
videoUrl += (videoUrl.endsWith('?') ? '' : '&') + 'download=true';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
}
|
| 507 |
+
|
| 508 |
+
// Use MediaSource for advanced buffering control if supported
|
| 509 |
+
if (window.MediaSource && MediaSource.isTypeSupported('video/mp4')) {
|
| 510 |
+
setupMediaSourcePlayer(videoUrl);
|
| 511 |
} else {
|
| 512 |
+
setupRegularPlayer(videoUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
}
|
| 514 |
+
|
| 515 |
+
// Show popup
|
| 516 |
+
playerPopup.classList.add('active');
|
| 517 |
+
|
| 518 |
+
// Disable scrolling on body when popup is active
|
| 519 |
+
document.body.style.overflow = 'hidden';
|
| 520 |
}
|
| 521 |
|
| 522 |
+
function setupMediaSourcePlayer(url) {
|
| 523 |
+
const mediaSource = new MediaSource();
|
| 524 |
+
videoPlayer.src = URL.createObjectURL(mediaSource);
|
| 525 |
+
|
| 526 |
+
mediaSource.addEventListener('sourceopen', function() {
|
| 527 |
+
const sourceBuffer = mediaSource.addSourceBuffer('video/mp4');
|
| 528 |
+
|
| 529 |
+
// Start loading the initial segment
|
| 530 |
+
fetchSegment(url, 0, 1024 * 1024 * 2) // First 2MB
|
| 531 |
+
.then(segment => {
|
| 532 |
+
sourceBuffer.addEventListener('updateend', function() {
|
| 533 |
+
if (!sourceBuffer.updating && mediaSource.readyState === 'open') {
|
| 534 |
+
mediaSource.endOfStream();
|
| 535 |
+
videoPlayer.play().catch(e => console.error('Play error:', e));
|
| 536 |
+
loadingSpinner.style.display = 'none';
|
| 537 |
+
|
| 538 |
+
// Start aggressive preloading
|
| 539 |
+
preloadNextSegments(videoPlayer.duration, url);
|
| 540 |
+
}
|
| 541 |
+
}, { once: true });
|
| 542 |
+
|
| 543 |
+
sourceBuffer.appendBuffer(segment);
|
| 544 |
+
})
|
| 545 |
+
.catch(error => {
|
| 546 |
+
console.error('Error loading initial segment:', error);
|
| 547 |
+
// Fallback to regular player
|
| 548 |
+
setupRegularPlayer(url);
|
| 549 |
+
});
|
| 550 |
+
|
| 551 |
+
// Handle seeking
|
| 552 |
+
videoPlayer.addEventListener('seeking', function() {
|
| 553 |
+
if (!isSeeking && mediaSource.readyState === 'open') {
|
| 554 |
+
isSeeking = true;
|
| 555 |
+
const targetTime = videoPlayer.currentTime;
|
| 556 |
+
seekPreview.textContent = formatTime(targetTime);
|
| 557 |
+
seekPreview.style.display = 'block';
|
| 558 |
+
|
| 559 |
+
// Load segment around seek position
|
| 560 |
+
const segmentStart = Math.max(0, targetTime - 2);
|
| 561 |
+
const segmentEnd = Math.min(videoPlayer.duration, targetTime + 2);
|
| 562 |
+
|
| 563 |
+
fetchByteRange(url, segmentStart, segmentEnd)
|
| 564 |
+
.then(segment => {
|
| 565 |
+
sourceBuffer.appendBuffer(segment);
|
| 566 |
+
seekPreview.style.display = 'none';
|
| 567 |
+
isSeeking = false;
|
| 568 |
+
})
|
| 569 |
+
.catch(error => {
|
| 570 |
+
console.error('Seek error:', error);
|
| 571 |
+
seekPreview.style.display = 'none';
|
| 572 |
+
isSeeking = false;
|
| 573 |
+
});
|
| 574 |
}
|
| 575 |
});
|
| 576 |
+
});
|
| 577 |
+
|
| 578 |
+
setupPlayerEventListeners();
|
| 579 |
+
}
|
| 580 |
|
| 581 |
+
function setupRegularPlayer(url) {
|
| 582 |
+
videoPlayer.src = url;
|
| 583 |
+
videoPlayer.load();
|
| 584 |
+
|
| 585 |
+
// Set up event listeners for immediate playback
|
| 586 |
+
videoPlayer.addEventListener('canplaythrough', function() {
|
| 587 |
+
loadingSpinner.style.display = 'none';
|
| 588 |
+
videoPlayer.play().catch(e => console.error('Play error:', e));
|
| 589 |
+
|
| 590 |
+
// Start aggressive preloading
|
| 591 |
+
preloadNextSegments(videoPlayer.duration, url);
|
| 592 |
+
}, { once: true });
|
| 593 |
+
|
| 594 |
+
videoPlayer.addEventListener('seeking', function() {
|
| 595 |
+
const targetTime = videoPlayer.currentTime;
|
| 596 |
+
seekPreview.textContent = formatTime(targetTime);
|
| 597 |
+
seekPreview.style.display = 'block';
|
| 598 |
+
|
| 599 |
+
setTimeout(() => {
|
| 600 |
+
seekPreview.style.display = 'none';
|
| 601 |
+
}, 1000);
|
| 602 |
+
});
|
| 603 |
+
|
| 604 |
+
setupPlayerEventListeners();
|
| 605 |
+
}
|
| 606 |
|
| 607 |
+
function preloadNextSegments(duration, url) {
|
| 608 |
+
if (!duration || duration === Infinity) return;
|
| 609 |
+
|
| 610 |
+
const currentTime = videoPlayer.currentTime;
|
| 611 |
+
const segmentSize = 1024 * 1024 * 4; // 4MB segments
|
| 612 |
+
|
| 613 |
+
// Preload next 3 segments ahead
|
| 614 |
+
for (let i = 1; i <= 3; i++) {
|
| 615 |
+
const segmentStart = currentTime + (i * 5);
|
| 616 |
+
if (segmentStart >= duration) break;
|
| 617 |
+
|
| 618 |
+
const segmentEnd = Math.min(duration, segmentStart + 5);
|
| 619 |
+
const segmentKey = `${Math.floor(segmentStart)}-${Math.floor(segmentEnd)}`;
|
| 620 |
+
|
| 621 |
+
if (!preloadedSegments.has(segmentKey)) {
|
| 622 |
+
preloadedSegments.add(segmentKey);
|
| 623 |
+
|
| 624 |
+
// Just trigger the download, we don't need the data for regular playback
|
| 625 |
+
fetchByteRange(url, segmentStart, segmentEnd)
|
| 626 |
+
.catch(error => console.error('Preload error:', error));
|
| 627 |
+
}
|
| 628 |
}
|
| 629 |
}
|
| 630 |
|
| 631 |
+
async function fetchSegment(url, start, end) {
|
| 632 |
+
const response = await fetch(url, {
|
| 633 |
+
headers: {
|
| 634 |
+
'Range': `bytes=${start}-${end}`
|
| 635 |
+
}
|
| 636 |
+
});
|
| 637 |
+
|
| 638 |
+
if (!response.ok) {
|
| 639 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 640 |
}
|
| 641 |
+
|
| 642 |
+
return response.arrayBuffer();
|
| 643 |
+
}
|
| 644 |
|
| 645 |
+
async function fetchByteRange(url, startTime, endTime) {
|
| 646 |
+
// Estimate byte range based on time (approximation)
|
| 647 |
+
const duration = videoPlayer.duration || 60; // Fallback to 60s if unknown
|
| 648 |
+
const fileSize = await getFileSize(url);
|
| 649 |
+
const startByte = Math.floor((startTime / duration) * fileSize);
|
| 650 |
+
const endByte = Math.floor((endTime / duration) * fileSize);
|
| 651 |
+
|
| 652 |
+
return fetchSegment(url, startByte, endByte);
|
| 653 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
|
| 655 |
+
async function getFileSize(url) {
|
| 656 |
try {
|
| 657 |
+
const response = await fetch(url, { method: 'HEAD' });
|
| 658 |
+
if (response.ok) {
|
| 659 |
+
const contentLength = response.headers.get('Content-Length');
|
| 660 |
+
return parseInt(contentLength) || 100 * 1024 * 1024; // Fallback to 100MB
|
| 661 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
} catch (error) {
|
| 663 |
+
console.error('Error getting file size:', error);
|
|
|
|
|
|
|
| 664 |
}
|
| 665 |
+
return 100 * 1024 * 1024; // Default fallback
|
| 666 |
}
|
| 667 |
|
| 668 |
+
function setupPlayerEventListeners() {
|
| 669 |
+
// Play/Pause button
|
| 670 |
+
playPauseBtn.addEventListener('click', togglePlayPause);
|
| 671 |
+
|
| 672 |
+
// Backward/Forward buttons
|
| 673 |
+
backwardBtn.addEventListener('click', () => seekRelative(-10));
|
| 674 |
+
forwardBtn.addEventListener('click', () => seekRelative(10));
|
| 675 |
+
|
| 676 |
+
// Fullscreen button
|
| 677 |
+
fullscreenBtn.addEventListener('click', toggleFullscreen);
|
| 678 |
+
|
| 679 |
+
// Mute button
|
| 680 |
+
muteBtn.addEventListener('click', toggleMute);
|
| 681 |
+
|
| 682 |
+
// Player events
|
| 683 |
+
videoPlayer.addEventListener('play', () => {
|
| 684 |
+
playPauseBtn.textContent = '⏸️ Pause';
|
| 685 |
+
});
|
| 686 |
+
|
| 687 |
+
videoPlayer.addEventListener('pause', () => {
|
| 688 |
+
playPauseBtn.textContent = '⏯️ Play';
|
| 689 |
+
});
|
| 690 |
+
|
| 691 |
+
videoPlayer.addEventListener('waiting', () => {
|
| 692 |
+
bufferingIndicator.style.display = 'block';
|
| 693 |
+
});
|
| 694 |
+
|
| 695 |
+
videoPlayer.addEventListener('playing', () => {
|
| 696 |
+
bufferingIndicator.style.display = 'none';
|
| 697 |
+
});
|
| 698 |
+
|
| 699 |
+
videoPlayer.addEventListener('timeupdate', () => {
|
| 700 |
+
// Continuously preload ahead
|
| 701 |
+
preloadNextSegments(videoPlayer.duration, videoPlayer.src);
|
| 702 |
+
});
|
| 703 |
+
|
| 704 |
+
videoPlayer.addEventListener('error', (e) => {
|
| 705 |
+
console.error('Video error:', videoPlayer.error);
|
| 706 |
+
loadingSpinner.style.display = 'none';
|
| 707 |
+
bufferingIndicator.style.display = 'none';
|
| 708 |
+
});
|
| 709 |
+
}
|
| 710 |
|
| 711 |
+
function togglePlayPause() {
|
| 712 |
+
if (videoPlayer.paused) {
|
| 713 |
+
videoPlayer.play().catch(error => {
|
| 714 |
+
console.error('Error playing video:', error);
|
| 715 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
} else {
|
| 717 |
+
videoPlayer.pause();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
}
|
|
|
|
| 719 |
}
|
| 720 |
|
| 721 |
+
function seekRelative(seconds) {
|
| 722 |
+
const newTime = Math.max(0, Math.min(videoPlayer.duration, videoPlayer.currentTime + seconds));
|
| 723 |
+
videoPlayer.currentTime = newTime;
|
| 724 |
+
|
| 725 |
+
// Show seek preview
|
| 726 |
+
seekPreview.textContent = formatTime(newTime);
|
| 727 |
+
seekPreview.style.display = 'block';
|
| 728 |
+
setTimeout(() => {
|
| 729 |
+
seekPreview.style.display = 'none';
|
| 730 |
+
}, 1000);
|
| 731 |
}
|
| 732 |
|
| 733 |
+
function formatTime(seconds) {
|
| 734 |
+
const mins = Math.floor(seconds / 60);
|
| 735 |
+
const secs = Math.floor(seconds % 60);
|
| 736 |
+
return `${mins}:${secs < 10 ? '0' : ''}${secs}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
}
|
| 738 |
|
| 739 |
+
function toggleFullscreen() {
|
| 740 |
+
if (!document.fullscreenElement) {
|
| 741 |
+
if (playerPopup.requestFullscreen) {
|
| 742 |
+
playerPopup.requestFullscreen();
|
| 743 |
+
} else if (playerPopup.webkitRequestFullscreen) {
|
| 744 |
+
playerPopup.webkitRequestFullscreen();
|
| 745 |
+
} else if (playerPopup.msRequestFullscreen) {
|
| 746 |
+
playerPopup.msRequestFullscreen();
|
| 747 |
}
|
| 748 |
} else {
|
| 749 |
+
if (document.exitFullscreen) {
|
| 750 |
+
document.exitFullscreen();
|
| 751 |
+
} else if (document.webkitExitFullscreen) {
|
| 752 |
+
document.webkitExitFullscreen();
|
| 753 |
+
} else if (document.msExitFullscreen) {
|
| 754 |
+
document.msExitFullscreen();
|
| 755 |
}
|
| 756 |
}
|
| 757 |
}
|
| 758 |
|
| 759 |
+
function toggleMute() {
|
| 760 |
+
videoPlayer.muted = !videoPlayer.muted;
|
| 761 |
+
muteBtn.textContent = videoPlayer.muted ? '🔇 Unmute' : '🔊 Mute';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 762 |
}
|
| 763 |
|
| 764 |
+
// Close popup function
|
| 765 |
+
function closePlayerPopup() {
|
| 766 |
+
videoPlayer.pause();
|
| 767 |
+
if (videoPlayer.src.startsWith('blob:')) {
|
| 768 |
+
URL.revokeObjectURL(videoPlayer.src);
|
|
|
|
|
|
|
|
|
|
| 769 |
}
|
| 770 |
+
videoPlayer.src = '';
|
| 771 |
+
playerPopup.classList.remove('active');
|
| 772 |
+
document.body.style.overflow = '';
|
| 773 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 774 |
|
| 775 |
// Search functionality
|
| 776 |
searchInput.addEventListener('input', function() {
|
| 777 |
+
const searchTerm = this.value.toLowerCase();
|
| 778 |
+
filteredVideos = videoData.filter(video =>
|
| 779 |
video.title.toLowerCase().includes(searchTerm)
|
| 780 |
);
|
| 781 |
currentPage = 1; // Reset to first page on search
|
| 782 |
renderPagination();
|
| 783 |
renderVideoGrid();
|
|
|
|
| 784 |
});
|
| 785 |
|
| 786 |
+
// Close popup when clicking close button
|
| 787 |
closePopup.addEventListener('click', closePlayerPopup);
|
| 788 |
|
| 789 |
+
// Close popup when clicking outside content
|
| 790 |
+
playerPopup.addEventListener('click', function(e) {
|
| 791 |
+
if (e.target === playerPopup) {
|
| 792 |
closePlayerPopup();
|
| 793 |
}
|
|
|
|
| 794 |
});
|
| 795 |
|
| 796 |
+
// Keyboard controls (only active when popup is visible)
|
| 797 |
+
document.addEventListener('keydown', function(e) {
|
| 798 |
+
if (!playerPopup.classList.contains('active')) return;
|
| 799 |
+
|
| 800 |
+
switch(e.key) {
|
| 801 |
+
case ' ': // Space
|
| 802 |
+
togglePlayPause();
|
| 803 |
+
e.preventDefault();
|
| 804 |
+
break;
|
| 805 |
+
case 'ArrowRight':
|
| 806 |
+
seekRelative(10);
|
| 807 |
+
e.preventDefault();
|
| 808 |
+
break;
|
| 809 |
+
case 'ArrowLeft':
|
| 810 |
+
seekRelative(-10);
|
| 811 |
+
e.preventDefault();
|
| 812 |
+
break;
|
| 813 |
+
case 'f':
|
| 814 |
+
case 'F':
|
| 815 |
+
toggleFullscreen();
|
| 816 |
+
e.preventDefault();
|
| 817 |
+
break;
|
| 818 |
+
case 'm':
|
| 819 |
+
case 'M':
|
| 820 |
+
toggleMute();
|
| 821 |
+
e.preventDefault();
|
| 822 |
+
break;
|
| 823 |
+
case 'Escape':
|
| 824 |
+
closePlayerPopup();
|
| 825 |
+
e.preventDefault();
|
| 826 |
+
break;
|
| 827 |
}
|
| 828 |
});
|
| 829 |
|
| 830 |
+
// Double tap controls for mobile/touch devices
|
| 831 |
+
let lastTap = 0;
|
| 832 |
+
let tapTimeout;
|
| 833 |
+
|
| 834 |
+
videoPlayer.addEventListener('click', function(e) {
|
| 835 |
+
const currentTime = new Date().getTime();
|
| 836 |
+
const tapLength = currentTime - lastTap;
|
| 837 |
+
clearTimeout(tapTimeout);
|
| 838 |
+
|
| 839 |
+
if (tapLength < 500 && tapLength > 0) {
|
| 840 |
+
// Double tap detected
|
| 841 |
+
const playerRect = videoPlayer.getBoundingClientRect();
|
| 842 |
+
const clickX = e.clientX - playerRect.left;
|
| 843 |
+
const playerWidth = playerRect.width;
|
| 844 |
+
|
| 845 |
+
// Determine click position (left, center, or right third)
|
| 846 |
+
if (clickX < playerWidth / 3) {
|
| 847 |
+
// Left side - backward
|
| 848 |
+
seekRelative(-10);
|
| 849 |
+
} else if (clickX > (playerWidth * 2) / 3) {
|
| 850 |
+
// Right side - forward
|
| 851 |
+
seekRelative(10);
|
| 852 |
+
} else {
|
| 853 |
+
// Center - play/pause
|
| 854 |
+
togglePlayPause();
|
| 855 |
+
}
|
| 856 |
+
e.preventDefault();
|
| 857 |
+
} else {
|
| 858 |
+
// Single tap - wait to see if it becomes a double tap
|
| 859 |
+
tapTimeout = setTimeout(function() {
|
| 860 |
+
// Single tap action (toggle controls visibility)
|
| 861 |
+
if (videoPlayer.hasAttribute('controls')) {
|
| 862 |
+
videoPlayer.removeAttribute('controls');
|
| 863 |
+
} else {
|
| 864 |
+
videoPlayer.setAttribute('controls', '');
|
| 865 |
+
}
|
| 866 |
+
}, 300);
|
| 867 |
+
}
|
| 868 |
+
lastTap = currentTime;
|
| 869 |
+
});
|
| 870 |
|
| 871 |
+
// Initialize
|
| 872 |
+
fetchVideoData();
|
| 873 |
</script>
|
|
|
|
| 874 |
</body>
|
| 875 |
</html>
|