33# Released under the terms of the BSD 3-Clause License
44
55from qtpy .QtCore import QUrl
6- from qtpy .QtMultimedia import QAudioOutput , QMediaPlayer
6+ from qtpy .QtMultimedia import QMediaPlayer
7+ try : # Qt 6
8+ from qtpy .QtMultimedia import QAudioOutput # type: ignore
9+ except ImportError : # Qt 5 fallback
10+ QAudioOutput = None # type: ignore
11+
12+ try : # Qt 5 fallback
13+ from qtpy .QtMultimedia import QMediaContent # type: ignore
14+ except ImportError : # Qt 6
15+ QMediaContent = None # type: ignore
716from qtpy .QtWidgets import QFrame
817
918from robot_log_visualizer .ui .ui_loader import load_ui
@@ -16,12 +25,25 @@ def __init__(self, video_filename: str):
1625 self .ui = load_ui ("video_tab.ui" , self )
1726
1827 self .media_player = QMediaPlayer (self )
19- self .audio_output = QAudioOutput (self )
20- self .media_player .setAudioOutput (self .audio_output )
28+
29+ self .audio_output = None
30+ if QAudioOutput is not None and hasattr (self .media_player , "setAudioOutput" ):
31+ self .audio_output = QAudioOutput (parent = self )
32+ self .media_player .setAudioOutput (self .audio_output )
33+
2134 self .media_player .setVideoOutput (self .ui .webcamView )
2235
2336 self .media_loaded = False
2437
2538 if os .path .isfile (video_filename ):
26- self .media_player .setSource (QUrl .fromLocalFile (video_filename ))
39+ url = QUrl .fromLocalFile (video_filename )
40+ if hasattr (self .media_player , "setSource" ):
41+ self .media_player .setSource (url )
42+ elif hasattr (self .media_player , "setMedia" ):
43+ if QMediaContent is not None :
44+ self .media_player .setMedia (QMediaContent (url ))
45+ else :
46+ self .media_player .setMedia (url )
47+ else :
48+ raise AttributeError ("QMediaPlayer backend missing media source setter" )
2749 self .media_loaded = True
0 commit comments