import React, { useEffect, useRef, useState, useMemo } from 'react'; import videojs from 'video.js'; import 'video.js/dist/video-js.css'; // Import the separated components import EndScreenOverlay from '../overlays/EndScreenOverlay'; import ChapterMarkers from '../markers/ChapterMarkers'; import NextVideoButton from '../controls/NextVideoButton'; import CustomRemainingTime from '../controls/CustomRemainingTime'; function VideoJSPlayer() { const videoRef = useRef(null); const playerRef = useRef(null); // Track the player instance // Safely access window.MEDIA_DATA with fallback using useMemo const mediaData = useMemo( () => typeof window !== 'undefined' && window.MEDIA_DATA ? window.MEDIA_DATA : { data: {}, siteUrl: '', hasNextLink: true, }, [] ); // Define chapters as JSON object // Note: The sample-chapters.vtt file is no longer needed as chapters are now loaded from this JSON const chaptersData = [ { startTime: 0, endTime: 5, text: 'Start111' }, { startTime: 5, endTime: 10, text: 'Introduction - EuroHPC' }, { startTime: 10, endTime: 15, text: 'Planning - EuroHPC' }, { startTime: 15, endTime: 20, text: 'Parcel Discounts - EuroHPC' }, { startTime: 20, endTime: 25, text: 'Class Studies - EuroHPC' }, { startTime: 25, endTime: 30, text: 'Sustainability - EuroHPC' }, { startTime: 30, endTime: 35, text: 'Funding and Finance - EuroHPC' }, { startTime: 35, endTime: 40, text: 'Virtual HPC Academy - EuroHPC' }, { startTime: 40, endTime: 45, text: 'Wrapping up - EuroHPC' }, ]; // Get video data from mediaData const currentVideo = useMemo( () => ({ id: mediaData.data?.friendly_token || 'default-video', title: mediaData.data?.title || 'Video', poster: mediaData.siteUrl + mediaData.data?.poster_url || '', sources: mediaData.data?.original_media_url ? [ { src: mediaData.siteUrl + mediaData.data.original_media_url, type: 'video/mp4', }, ] : [ { src: '/videos/sample-video.mp4', type: 'video/mp4', }, ], }), [mediaData] ); // Mock related videos data (would come from API) const [relatedVideos] = useState([ { id: 'Otbc37Yj4', title: 'Amazing Ocean Depths', author: 'Marine Explorer', views: '2.1M views', thumbnail: 'https://picsum.photos/320/180?random=1', category: 'nature', }, { id: 'Kt9m2Pv8x', title: 'Deep Sea Creatures', author: 'Aquatic Life', views: '854K views', thumbnail: 'https://picsum.photos/320/180?random=2', category: 'nature', }, { id: 'Ln5q8Bw3r', title: 'Coral Reef Paradise', author: 'Ocean Films', views: '1.7M views', thumbnail: 'https://picsum.photos/320/180?random=3', category: 'nature', }, { id: 'Mz4x7Cy9p', title: 'Underwater Adventure', author: 'Sea Documentaries', views: '3.2M views', thumbnail: 'https://picsum.photos/320/180?random=4', category: 'nature', }, { id: 'Nx8v2Fk6w', title: 'Marine Wildlife', author: 'Nature Plus', views: '967K views', thumbnail: 'https://picsum.photos/320/180?random=5', category: 'nature', }, { id: 'Py7t4Mn1q', title: 'Ocean Mysteries', author: 'Discovery Zone', views: '1.4M views', thumbnail: 'https://picsum.photos/320/180?random=6', category: 'nature', }, { id: 'Qw5e8Rt2n', title: 'Whales and Dolphins', author: 'Ocean Planet', views: '2.8M views', thumbnail: 'https://picsum.photos/320/180?random=7', category: 'nature', }, { id: 'Uv3k9Lp7m', title: 'Tropical Fish Paradise', author: 'Aquatic World', views: '1.2M views', thumbnail: 'https://picsum.photos/320/180?random=8', category: 'nature', }, { id: 'Zx6c4Mn8b', title: 'Deep Ocean Exploration', author: 'Marine Science', views: '3.7M views', thumbnail: 'https://picsum.photos/320/180?random=9', category: 'nature', }, ]); // Function to navigate to next video const goToNextVideo = () => { console.log('Next video functionality disabled for single video mode'); if (mediaData.onClickNextCallback && typeof mediaData.onClickNextCallback === 'function') { mediaData.onClickNextCallback(); } }; useEffect(() => { // Only initialize if we don't already have a player and element exists if (videoRef.current && !playerRef.current) { // Check if element is already a Video.js player if (videoRef.current.player) { // console.log('Video.js already initialized on this element'); return; } const timer = setTimeout(() => { // Double-check that we still don't have a player and element exists if (!playerRef.current && videoRef.current && !videoRef.current.player) { playerRef.current = videojs(videoRef.current, { // ===== STANDARD