Fixed crashes

parent 89aa1260
...@@ -1998,6 +1998,22 @@ class WebPlayerWindow(QMainWindow): ...@@ -1998,6 +1998,22 @@ class WebPlayerWindow(QMainWindow):
def setup_web_player(self): def setup_web_player(self):
"""Setup web player with QWebEngineView""" """Setup web player with QWebEngineView"""
# Configure web engine settings to allow autoplay
from PyQt6.QtWebEngineCore import QWebEngineSettings
settings = self.web_player_view.settings()
settings.setAttribute(QWebEngineSettings.WebAttribute.PlaybackRequiresUserGesture, False)
settings.setAttribute(QWebEngineSettings.WebAttribute.AllowRunningInsecureContent, True)
settings.setAttribute(QWebEngineSettings.WebAttribute.AllowGeolocationOnInsecureOrigins, True)
settings.setAttribute(QWebEngineSettings.WebAttribute.LocalContentCanAccessRemoteUrls, True)
settings.setAttribute(QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls, True)
logger.info("Configured web engine settings to allow autoplay and local content")
# Configure web engine profile for local file access
profile = self.web_player_view.page().profile()
profile.setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
profile.setPersistentCookiesPolicy(QWebEngineProfile.PersistentCookiesPolicy.NoPersistentCookies)
logger.info("Configured web engine profile for local file access")
# Get web player HTML path # Get web player HTML path
web_player_html_path = self._get_web_player_html_path() web_player_html_path = self._get_web_player_html_path()
......
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
<body> <body>
<!-- Video container --> <!-- Video container -->
<div class="video-container"> <div class="video-container">
<video id="webVideoPlayer" controls autoplay playsinline> <video id="webVideoPlayer" controls playsinline muted>
<source src="" type="video/mp4"> <source src="" type="video/mp4">
Your browser does not support the video tag. Your browser does not support the video tag.
</video> </video>
......
...@@ -191,6 +191,26 @@ class WebPlayerAPI { ...@@ -191,6 +191,26 @@ class WebPlayerAPI {
console.log('Video readyState:', this.videoElement.readyState); console.log('Video readyState:', this.videoElement.readyState);
console.log('Video networkState:', this.videoElement.networkState); console.log('Video networkState:', this.videoElement.networkState);
console.log('Video error:', this.videoElement.error); console.log('Video error:', this.videoElement.error);
// For debug mode, ensure video is visible and properly sized
if (window.location.href.includes('debug') || window.location.href.includes('debug-player')) {
console.log('DEBUG MODE: Ensuring video visibility');
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
this.videoElement.style.width = '100%';
this.videoElement.style.height = '100%';
this.videoElement.style.objectFit = 'contain';
// Force video element to be visible in debug mode
const videoContainer = document.querySelector('.video-container');
if (videoContainer) {
videoContainer.style.display = 'block';
videoContainer.style.visibility = 'visible';
videoContainer.style.opacity = '1';
videoContainer.style.zIndex = '100';
}
}
} }
// Attempt playback with autoplay policy handling // Attempt playback with autoplay policy handling
...@@ -201,9 +221,21 @@ class WebPlayerAPI { ...@@ -201,9 +221,21 @@ class WebPlayerAPI {
if (this.videoElement.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) { if (this.videoElement.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) {
console.log('Video ready, attempting playback...'); console.log('Video ready, attempting playback...');
// For debug mode, ensure video is visible before attempting playback
if (window.location.href.includes('debug') || window.location.href.includes('debug-player')) {
console.log('DEBUG MODE: Ensuring video is visible before playback');
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
}
// Try to play with autoplay policy handling // Try to play with autoplay policy handling
this.videoElement.play().then(() => { this.videoElement.play().then(() => {
console.log('Playback started successfully'); console.log('Playback started successfully');
// Ensure video is visible after successful playback
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
}).catch(e => { }).catch(e => {
console.error('Playback failed (likely due to autoplay policy):', e); console.error('Playback failed (likely due to autoplay policy):', e);
...@@ -211,6 +243,14 @@ class WebPlayerAPI { ...@@ -211,6 +243,14 @@ class WebPlayerAPI {
this.videoElement.controls = true; this.videoElement.controls = true;
this.videoElement.muted = true; // Muted videos can often autoplay this.videoElement.muted = true; // Muted videos can often autoplay
// For debug mode, ensure video is visible even if autoplay fails
if (window.location.href.includes('debug') || window.location.href.includes('debug-player')) {
console.log('DEBUG MODE: Forcing video visibility despite autoplay block');
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
}
// Try again with muted // Try again with muted
this.videoElement.play().catch(e2 => { this.videoElement.play().catch(e2 => {
console.error('Muted playback also failed:', e2); console.error('Muted playback also failed:', e2);
...@@ -219,6 +259,13 @@ class WebPlayerAPI { ...@@ -219,6 +259,13 @@ class WebPlayerAPI {
}); });
} else { } else {
console.log('Video not ready yet, waiting for more data...'); console.log('Video not ready yet, waiting for more data...');
// For debug mode, ensure video is visible even while waiting
if (window.location.href.includes('debug') || window.location.href.includes('debug-player')) {
console.log('DEBUG MODE: Ensuring video is visible while waiting for data');
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
}
} }
} }
...@@ -325,4 +372,54 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -325,4 +372,54 @@ document.addEventListener('DOMContentLoaded', function() {
console.log('Web Player API initialized and exposed to window.webPlayer'); console.log('Web Player API initialized and exposed to window.webPlayer');
console.log('Global functions playVideo and updateOverlayData exposed for WebChannel'); console.log('Global functions playVideo and updateOverlayData exposed for WebChannel');
});
\ No newline at end of file // Initialize debug mode if detected
if (window.location.href.includes('debug') || window.location.href.includes('debug-player')) {
console.log('DEBUG MODE DETECTED: Applying debug-specific video fixes');
webPlayer._initDebugMode();
}
});
// Add debug mode initialization method to WebPlayerAPI prototype
WebPlayerAPI.prototype._initDebugMode = function() {
console.log('Initializing debug mode for web player');
// Ensure video element is visible in debug mode
if (this.videoElement) {
this.videoElement.style.display = 'block';
this.videoElement.style.visibility = 'visible';
this.videoElement.style.opacity = '1';
this.videoElement.style.width = '100%';
this.videoElement.style.height = '100%';
this.videoElement.style.objectFit = 'contain';
this.videoElement.muted = true; // Ensure muted for autoplay in debug mode
// Force video container to be visible
const videoContainer = document.querySelector('.video-container');
if (videoContainer) {
videoContainer.style.display = 'block';
videoContainer.style.visibility = 'visible';
videoContainer.style.opacity = '1';
videoContainer.style.zIndex = '100';
}
// Add debug overlay to indicate debug mode
const debugOverlay = document.createElement('div');
debugOverlay.style.position = 'absolute';
debugOverlay.style.top = '10px';
debugOverlay.style.right = '10px';
debugOverlay.style.backgroundColor = 'rgba(255, 0, 0, 0.7)';
debugOverlay.style.color = 'white';
debugOverlay.style.padding = '5px 10px';
debugOverlay.style.borderRadius = '5px';
debugOverlay.style.fontFamily = 'Arial, sans-serif';
debugOverlay.style.fontSize = '14px';
debugOverlay.style.zIndex = '1000';
debugOverlay.textContent = 'DEBUG MODE - Video Player';
document.body.appendChild(debugOverlay);
console.log('Debug mode initialization completed');
} else {
console.error('DEBUG MODE: Video element not available for debug initialization');
}
};
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment