Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const videoUrlInput = document.getElementById('video-url');
+ const languageSelect = document.getElementById('language-select');
+ const generateBtn = document.getElementById('generate-btn');
+ const resultSection = document.querySelector('.result-section');
+ const videoElement = document.querySelector('video');
+ const subtitleTrack = document.querySelector('track');
+ const subtitleText = document.querySelector('.subtitle-text');
+
+ generateBtn.addEventListener('click', async () => {
+ const videoUrl = videoUrlInput.value;
+ const language = languageSelect.value;
+
+ if (!videoUrl) {
+ alert('Please enter a video URL');
+ return;
+ }
+
+ try {
+ // Simulate subtitle generation (replace with actual API call)
+ const subtitles = await generateSubtitles(videoUrl, language);
+
+ // Update video source and subtitles
+ videoElement.src = videoUrl;
+ subtitleTrack.src = subtitles;
+
+ // Show result section
+ resultSection.classList.remove('hidden');
+
+ // Update displayed subtitle text
+ videoElement.textTracks[0].mode = 'hidden';
+ videoElement.textTracks[0].oncuechange = () => {
+ const cue = videoElement.textTracks[0].activeCues[0];
+ subtitleText.textContent = cue ? cue.text : '';
+ };
+ } catch (error) {
+ console.error('Error:', error);
+ alert('Failed to generate subtitles. Please try again.');
+ }
+ });
+
+ // Mock subtitle generation function
+ function generateSubtitles(videoUrl, language) {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ // This would be replaced with actual subtitle file URL
+ resolve(`/subtitles/${language}.vtt`);
+ }, 1000);
+ });
+ }
+ });