Update player.js

This commit is contained in:
Anirudh Sevugan 2025-04-24 19:17:53 -05:00 committed by GitHub
parent f288cf7aa7
commit e3c8d282ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,8 @@ document.addEventListener('DOMContentLoaded', () => {
const submitSubtitlesBtn = document.getElementById('submitSubtitlesBtn'); const submitSubtitlesBtn = document.getElementById('submitSubtitlesBtn');
const cancelSubtitlesBtn = document.getElementById('cancelSubtitlesBtn'); const cancelSubtitlesBtn = document.getElementById('cancelSubtitlesBtn');
const customControls = document.getElementById('customControls'); const customControls = document.getElementById('customControls');
let hls = null
let player = null
// Update media volume when the slider is moved // Update media volume when the slider is moved
volumeBar.addEventListener("input", function () { volumeBar.addEventListener("input", function () {
@ -97,14 +99,23 @@ submitUrlBtn.addEventListener('click', () => {
// Assuming it's a URL and needs the protocol added // Assuming it's a URL and needs the protocol added
url = 'http://' + url; // You can also choose 'https://' if preferred url = 'http://' + url; // You can also choose 'https://' if preferred
} }
if (url) { if (url) {
clearSubtitles(); clearSubtitles();
if (url.includes('.m3u8')) { if (hls !== null) {
hls.destroy()
hls = null
}
if (player !== null) {
player.reset()
player = null
}
if (url.toLowerCase().includes('.m3u8') || url.toLowerCase().includes('.m3u')) {
// HLS stream // HLS stream
if (Hls.isSupported()) { if (Hls.isSupported()) {
mediaPlayer.style.display = 'flex'; // Hide the native video playerz mediaPlayer.style.display = 'flex'; // Hide the native video player
const hls = new Hls(); hls = new Hls();
mediaPlayer.pause(); mediaPlayer.pause();
hls.loadSource(url); hls.loadSource(url);
hls.attachMedia(mediaPlayer); hls.attachMedia(mediaPlayer);
@ -116,14 +127,14 @@ submitUrlBtn.addEventListener('click', () => {
customControls.style.display = 'flex'; customControls.style.display = 'flex';
}); });
} else { } else {
alert("HLS isn't supported on your browser."); alert("Your device doesn't support HLS.");
customControls.style.display = 'flex'; customControls.style.display = 'flex';
urlInput.value = ""; urlInput.value = "";
} }
} else if (url.includes('.mpd')) { } else if (url.toLowerCase().includes('.mpd')) {
mediaPlayer.style.display = 'flex'; // Hide the native video player mediaPlayer.style.display = 'flex'; // Hide the native video player
mediaPlayer.pause(); mediaPlayer.pause();
const player = dashjs.MediaPlayer().create(); player = dashjs.MediaPlayer().create();
// MPEG-DASH stream // MPEG-DASH stream
player.initialize(mediaPlayer, url, true); player.initialize(mediaPlayer, url, true);
customControls.style.display = 'flex'; customControls.style.display = 'flex';
@ -309,8 +320,14 @@ subtitlesInput.addEventListener('keydown', (e) => {
mediaPlayer.loop = loopEnabled; mediaPlayer.loop = loopEnabled;
const controlsEnabled = document.getElementById('controlsCheckbox').checked; const controlsEnabled = document.getElementById('controlsCheckbox').checked;
const colorsEnabled = document.getElementById('colorsCheckbox').checked;
mediaPlayer.controls = controlsEnabled; mediaPlayer.controls = controlsEnabled;
if (colorsEnabled) {
mediaPlayer.style.filter = "contrast(1.1) saturate(1.15) brightness(1.03)";
} else {
mediaPlayer.style.filter = "";
}
settingsPanel.style.display = 'none'; settingsPanel.style.display = 'none';
settingsDialogOverlay.style.display = 'none'; settingsDialogOverlay.style.display = 'none';
}); });