Update player.js

This commit is contained in:
Anirudh Sevugan 2025-02-17 14:02:34 +05:30 committed by GitHub
parent 78360af2d8
commit 8d11087975
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -154,17 +154,32 @@ submitUrlBtn.addEventListener('click', () => {
}); });
// Handle file input
let previousObjectURL = null; // Store the last Object URL
fileInput.addEventListener('change', (event) => { fileInput.addEventListener('change', (event) => {
const file = event.target.files[0]; const file = event.target.files[0];
if (file) { if (!file) return;
clearSubtitles();
clearSubtitles(); // Remove any previously loaded subtitles
// Revoke the previous Object URL if it exists
if (previousObjectURL) {
URL.revokeObjectURL(previousObjectURL);
}
// Create a new Object URL for the selected file
const fileURL = URL.createObjectURL(file); const fileURL = URL.createObjectURL(file);
mediaPlayer.src = fileURL; mediaPlayer.src = fileURL;
mediaPlayer.play();
// Store the new Object URL for future cleanup
previousObjectURL = fileURL;
// Hide dialog after selecting a file
dialogOverlay.style.display = 'none'; dialogOverlay.style.display = 'none';
}
}); });
// Handle "Enter a URL" button // Handle "Enter a URL" button
enterUrlBtn.addEventListener('click', () => { enterUrlBtn.addEventListener('click', () => {