Main error fixed, AI instruction added

parent a6e2ed18
- When you try to execute the application or pip, use . venv/bin/activate && python3 or pip3 ...
......@@ -56,8 +56,8 @@ class OverlayWebChannel(QObject):
consoleMessage = pyqtSignal(str, str, int, str) # level, message, line, source
# Signals for web player communication
playVideo = pyqtSignal(str) # filePath
updateOverlayData = pyqtSignal(dict) # overlay data
playVideoSignal = pyqtSignal(str) # filePath
updateOverlayDataSignal = pyqtSignal(dict) # overlay data
def __init__(self, db_manager=None, message_bus=None):
super().__init__()
......@@ -253,13 +253,13 @@ class OverlayWebChannel(QObject):
def playVideo(self, filePath: str):
"""Send play video command to JavaScript (called by Qt)"""
logger.info(f"OverlayWebChannel.playVideo called with: {filePath}")
self.playVideo.emit(filePath)
self.playVideoSignal.emit(filePath)
@pyqtSlot(dict)
def updateOverlayData(self, data: dict):
"""Send overlay data update to JavaScript (called by Qt)"""
logger.debug(f"OverlayWebChannel.updateOverlayData called with: {data}")
self.updateOverlayData.emit(data)
self.updateOverlayDataSignal.emit(data)
@pyqtSlot(int, result=str)
def getWinningBets(self, match_id: int) -> str:
......@@ -2113,16 +2113,36 @@ class WebPlayerWindow(QMainWindow):
self.web_player_view.page().setWebChannel(self.web_channel)
# Connect WebChannel signals to handle video playback and overlay updates
self.web_player_channel.playVideo.connect(self._handle_web_player_play_video)
self.web_player_channel.updateOverlayData.connect(self._handle_web_player_update_overlay)
# Connect signals from the instance, not the class
if hasattr(self.web_player_channel, 'playVideoSignal'):
self.web_player_channel.playVideoSignal.connect(self._handle_web_player_play_video)
logger.info("Connected playVideoSignal from web player channel")
else:
logger.error("web_player_channel.playVideoSignal not available")
# Add WebChannel JavaScript to the page
self._inject_webchannel_javascript()
if hasattr(self.web_player_channel, 'updateOverlayDataSignal'):
self.web_player_channel.updateOverlayDataSignal.connect(self._handle_web_player_update_overlay)
logger.info("Connected updateOverlayDataSignal from web player channel")
else:
logger.error("web_player_channel.updateOverlayDataSignal not available")
# Note: WebChannel JavaScript injection moved to _on_web_player_loaded()
# Add debug logging for WebChannel setup
logger.info("WebChannel setup completed for web player")
logger.info(f"WebChannel object: {self.web_channel}")
logger.info(f"Web player channel: {self.web_player_channel}")
logger.info(f"Web player channel playVideo signal: {self.web_player_channel.playVideo}")
logger.info(f"Web player channel updateOverlayData signal: {self.web_player_channel.updateOverlayData}")
# Check if signals have connect method
logger.info(f"playVideo has connect: {hasattr(self.web_player_channel.playVideo, 'connect')}")
logger.info(f"updateOverlayData has connect: {hasattr(self.web_player_channel.updateOverlayData, 'connect')}")
except Exception as e:
logger.error(f"Failed to setup WebChannel for web player: {e}")
import traceback
logger.error(f"WebChannel setup traceback: {traceback.format_exc()}")
def _on_web_player_loaded(self, ok=None):
"""Handle web player load completion"""
......@@ -2133,16 +2153,26 @@ class WebPlayerWindow(QMainWindow):
logger.info("Web player loaded successfully")
# Inject QWebChannel and WebPlayerAPI JavaScript now that page is loaded
self._inject_webchannel_javascript()
# Inject WebChannel setup into the page
self._inject_webchannel_setup()
# Add debug logging for WebChannel setup
logger.info("Web player load completed, WebChannel should be ready")
logger.info(f"WebChannel object: {self.web_channel}")
logger.info(f"Web player channel: {self.web_player_channel}")
except Exception as e:
logger.error(f"Failed to handle web player load: {e}")
import traceback
logger.error(f"Web player load traceback: {traceback.format_exc()}")
def _inject_webchannel_javascript(self):
"""Inject WebChannel JavaScript into the page"""
"""Inject WebChannel JavaScript and WebPlayerAPI into the page"""
try:
# Inject QWebChannel JavaScript library
# First inject QWebChannel JavaScript library
webchannel_js = """
// QWebChannel JavaScript library
var QWebChannel = (function() {
......@@ -2223,8 +2253,25 @@ class WebPlayerWindow(QMainWindow):
self.web_player_view.page().runJavaScript(webchannel_js)
# Then inject the WebPlayerAPI JavaScript
webplayer_js_path = Path(__file__).parent / "web_player_assets" / "web_player.js"
if webplayer_js_path.exists():
with open(webplayer_js_path, 'r', encoding='utf-8') as f:
webplayer_js_content = f.read()
# Wrap the web player JS in a script tag and inject it
full_js = f"""
// WebPlayerAPI JavaScript
{webplayer_js_content}
"""
self.web_player_view.page().runJavaScript(full_js)
logger.info("Injected WebPlayerAPI JavaScript after QWebChannel")
else:
logger.error(f"WebPlayerAPI JavaScript file not found: {webplayer_js_path}")
except Exception as e:
logger.error(f"Failed to inject WebChannel JavaScript: {e}")
logger.error(f"Failed to inject WebChannel and WebPlayerAPI JavaScript: {e}")
def _inject_webchannel_setup(self):
"""Inject WebChannel setup into the web player page"""
......
......@@ -297,9 +297,10 @@
<div class="venue-info" id="venueInfo">Loading venue...</div>
</div>
<!-- Load WebPlayerAPI JavaScript -->
<script src="web_player.js"></script>
<!-- Qt WebChannel JavaScript will be injected by Qt -->
<!-- Qt WebChannel JavaScript and WebPlayerAPI will be injected by Qt -->
<script>
// Set web server URL for video serving
window.webServerUrl = 'http://127.0.0.1:5001';
</script>
</body>
</html>
\ No newline at end of file
......@@ -84,14 +84,14 @@ class WebPlayerAPI {
});
}
if (this.overlayChannel.playVideo) {
this.overlayChannel.playVideo.connect((filePath) => {
if (this.overlayChannel.playVideoSignal) {
this.overlayChannel.playVideoSignal.connect((filePath) => {
this.playVideo(filePath);
});
}
if (this.overlayChannel.updateOverlayData) {
this.overlayChannel.updateOverlayData.connect((data) => {
if (this.overlayChannel.updateOverlayDataSignal) {
this.overlayChannel.updateOverlayDataSignal.connect((data) => {
this.handleOverlayData(data);
});
}
......@@ -112,6 +112,12 @@ class WebPlayerAPI {
console.log('Web player received overlay data:', data);
this.overlayData = data || {};
// Update web server URL if provided
if (data && data.webServerBaseUrl) {
window.webServerUrl = data.webServerBaseUrl;
console.log('Updated web server URL:', window.webServerUrl);
}
// Update UI with overlay data
this.updateUIFromOverlayData();
......@@ -193,8 +199,12 @@ class WebPlayerAPI {
videoContainer.style.height = '100%';
}
// Convert file path to web-accessible URL
const videoUrl = this.convertFilePathToUrl(filePath);
console.log('Converted file path to URL:', videoUrl);
// Set video source and load
this.videoElement.src = filePath;
this.videoElement.src = videoUrl;
// Add event listeners for better debugging
this.videoElement.onloadeddata = () => {
......@@ -209,6 +219,8 @@ class WebPlayerAPI {
this.videoElement.onerror = (e) => {
console.error('Video element error:', e);
console.error('Failed URL:', videoUrl);
console.error('Original path:', filePath);
this.sendPlayerError('load_failed', 'Failed to load video source');
};
......@@ -222,6 +234,31 @@ class WebPlayerAPI {
console.log('Video error:', this.videoElement.error);
}
// Convert file path to web-accessible URL
convertFilePathToUrl(filePath) {
// If it's already a URL, return as-is
if (filePath.startsWith('http://') || filePath.startsWith('https://')) {
return filePath;
}
// Extract filename from path
const pathParts = filePath.split(/[/\\]/);
const filename = pathParts[pathParts.length - 1];
// Construct URL using web server
const webServerUrl = window.webServerUrl || 'http://127.0.0.1:5001';
const videoUrl = `${webServerUrl}/video/${filename}`;
console.log('Converting file path to URL:', {
originalPath: filePath,
filename: filename,
webServerUrl: webServerUrl,
finalUrl: videoUrl
});
return videoUrl;
}
// Attempt playback with autoplay policy handling
_attemptPlayback() {
if (!this.videoElement) return;
......
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