diff --git a/assets/js/player.js b/assets/js/player.js index 0556e1bb..cd814971 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -58,43 +58,6 @@ try { player = videojs('player', options); console.log('[Invidious Debug] videojs initialized successfully.'); - // --- START WebOS DASH Workaround --- - var isWebOS = /Web[O0]S|LG Browser/i.test(navigator.userAgent); - console.log('[Invidious Debug] Checking for WebOS. User Agent:', navigator.userAgent, 'Is WebOS:', isWebOS); - - if (isWebOS && video_data.params.quality === 'dash') { - console.log('[Invidious Debug] WebOS detected with DASH quality. Attempting to filter sources.'); - // It might be too early here, sources might not be fully set. - // Let's try removing the source later, maybe on 'canplay' or 'sourceset' if needed. - // For now, just log the detection. We might need to hook into an event. - - // --- Alternative: Try filtering sources immediately (might not work) --- - try { - let currentSources = player.currentSources(); - console.log('[Invidious Debug] WebOS: Sources before filter:', JSON.stringify(currentSources)); - let filteredSources = currentSources.filter(function(source) { - return source.type !== 'application/dash+xml'; - }); - // Set filtered sources if different, find the non-DASH source - if (filteredSources.length > 0 && filteredSources.length < currentSources.length) { - console.log('[Invidious Debug] WebOS: Sources after filter:', JSON.stringify(filteredSources)); - // Select the first non-DASH source explicitly - let mp4Source = filteredSources.find(s => s.type.startsWith('video/mp4')); - if (mp4Source) { - console.log('[Invidious Debug] WebOS: Setting source explicitly to MP4:', JSON.stringify(mp4Source)); - player.src(mp4Source); // Try setting the source directly - } else { - console.warn('[Invidious Debug] WebOS: No suitable MP4 source found after filtering DASH.'); - } - } else { - console.log('[Invidious Debug] WebOS: No DASH source found to filter, or no other sources available.'); - } - } catch (e) { - console.error('[Invidious Debug] WebOS: Error filtering sources:', e); - } - } - // --- END WebOS DASH Workaround --- - } catch (e) { console.error('[Invidious Debug] videojs initialization FAILED:', e); // Stop further execution if player init fails @@ -102,7 +65,9 @@ try { } player.on('error', function () { - console.error('[Invidious Debug] Player error event triggered:', player.error()); + var error = player.error(); + console.error('[Invidious Debug] Player Error Event:', error ? error.message : 'Unknown error', 'Code:', error ? error.code : 'N/A', 'Type:', error ? error.type : 'N/A', error); + if (video_data.params.quality === 'dash') return; var localNotDisabled = ( @@ -142,6 +107,39 @@ player.on('error', function () { } }); +try { + player.on('error', function () { + var error = player.error(); + console.error('[Invidious Debug] Player Error Event:', error ? error.message : 'Unknown error', 'Code:', error ? error.code : 'N/A', 'Type:', error ? error.type : 'N/A', error); + + // Only reload if not dash or an ad is playing. + // Don't reload if the error is Source Not Supported type, as this is used when + }); + console.log('[Invidious Debug] Generic player error listener attached.'); + + // Add listener for tech errors (might give more specific MSE/network errors) + player.ready(function() { + const tech = player.tech_; + if (tech) { + tech.on('error', function(event) { + console.error('[Invidious Debug] Tech Error Event:', event); + if (tech.error) { + console.error('[Invidious Debug] Tech Error Details:', tech.error().message, 'Code:', tech.error().code); + } + }); + console.log('[Invidious Debug] Tech error listener attached.'); + } else { + console.warn('[Invidious Debug] Could not attach tech error listener.'); + } + }); +} catch (e) { + console.error('[Invidious Debug] FAILED attaching error listeners:', e); +} + +if (player.error) { + console.log('[Invidious Debug] Player error listener attached.'); +} + if (video_data.params.quality === 'dash') { console.log('[Invidious Debug] Initializing reloadSourceOnError...'); try { @@ -352,9 +350,42 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') { console.log('[Invidious Debug] Initializing httpSourceSelector...'); console.log('[Invidious Debug] Player sources BEFORE httpSourceSelector init:', JSON.stringify(player.currentSources())); try { - player.httpSourceSelector(); - console.log('[Invidious Debug] httpSourceSelector initialized.'); - console.log('[Invidious Debug] Player sources AFTER httpSourceSelector init:', JSON.stringify(player.currentSources())); + player.httpSourceSelector(); // This triggers manifest fetch & parsing + console.log('[Invidious Debug] httpSourceSelector initialized (call successful).'); // Log after call + console.log('[Invidious Debug] Player sources AFTER httpSourceSelector init call:', JSON.stringify(player.currentSources())); // Sources might not update yet + + // Add listener for source changes after httpSourceSelector + player.on('sourceset', function() { + console.log('[Invidious Debug] Event: sourceset triggered. Current sources:', JSON.stringify(player.currentSources())); // Log when sources actually change + }); + console.log('[Invidious Debug] sourceset listener attached.'); // Added + + // Listen for potential errors during quality level processing + player.ready(function () { + // Add listener for quality level errors + const qualityLevels = player.qualityLevels(); + if (qualityLevels) { + qualityLevels.on('error', function(event) { + console.error('[Invidious Debug] QualityLevels Error Event:', event); + }); + console.log('[Invidious Debug] QualityLevels error listener attached.'); // Added + + // Log initial quality levels once metadata is loaded + player.on('loadedmetadata', function() { + try { + console.log('[Invidious Debug] Event: loadedmetadata triggered.'); // Added + const levels = Array.from(player.qualityLevels()); + // Log detailed info about each level + console.log('[Invidious Debug] Quality levels after loadedmetadata:', JSON.stringify(levels.map(l => ({id: l.id, width: l.width, height: l.height, bitrate: l.bitrate, enabled: l.enabled})))); + } catch (e) { + console.error('[Invidious Debug] Error logging/processing quality levels:', e); // Added + } + }); + console.log('[Invidious Debug] loadedmetadata listener attached for quality level logging.'); // Added + } else { + console.warn('[Invidious Debug] Could not attach QualityLevels error listener or get levels.'); // Added + } + }); if (video_data.params.quality_dash !== 'auto') { console.log('[Invidious Debug] Setting DASH quality:', video_data.params.quality_dash); @@ -391,7 +422,7 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') { } } catch (e) { - console.error('[Invidious Debug] httpSourceSelector FAILED:', e); + console.error('[Invidious Debug] httpSourceSelector FAILED (call threw error):', e); // Log if the call itself fails } } @@ -819,7 +850,7 @@ addEventListener('keydown', function (e) { break; // TODO: More precise step. Now FPS is taken equal to 29.97 - // Common FPS: https://forum.videohelp.com/threads/81868#post323588 + // Common FPS: https://forum.videohelp.com/threads/81864#post323588 // Possible solution is new HTMLVideoElement.requestVideoFrameCallback() https://wicg.github.io/video-rvfc/ case ',': action = function () { pause(); skip_seconds(-1/29.97); }; break; case '.': action = function () { pause(); skip_seconds( 1/29.97); }; break;