Skip to content

Commit 0bdc115

Browse files
Update navigation_manager.py
Fixed a QMediaPlayer race condition where switching sources too quickly leaves the video surface uninitialized or locked, causing a black screen
1 parent b2d4d3f commit 0bdc115

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

annotation_tool/controllers/classification/navigation_manager.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from PyQt6.QtWidgets import QMessageBox, QFileDialog
3-
from PyQt6.QtCore import Qt, QModelIndex
3+
from PyQt6.QtCore import Qt, QModelIndex, QTimer
4+
# [Ref] Import from the correct models location
45
from models.project_tree import ProjectTreeModel
56
from utils import SUPPORTED_EXTENSIONS
67

@@ -87,11 +88,19 @@ def on_item_selected(self, current, previous):
8788
self.main.annot_manager.display_manual_annotation(path)
8889
self.ui.classification_ui.right_panel.manual_box.setEnabled(True)
8990

90-
# Update Center Panel (Video)
91+
# [FIX] Get player instance
92+
player = self.ui.classification_ui.center_panel.single_view_widget.player
93+
94+
# [FIX] Explicitly stop the player before loading a new source.
95+
# This helps reset the video pipeline and prevents black screens on some systems.
96+
player.stop()
97+
98+
# Update Center Panel (Video) - This loads the new source
9199
self.ui.classification_ui.center_panel.show_single_view(path)
92100

93-
# Force play when switching clips
94-
self.ui.classification_ui.center_panel.single_view_widget.player.play()
101+
# [FIX] Force play with increased delay (150ms).
102+
# 150ms-200ms is a safer buffer for PyQt6 QMediaPlayer.
103+
QTimer.singleShot(150, player.play)
95104

96105
def play_video(self):
97106
"""Toggle Play/Pause"""
@@ -153,7 +162,7 @@ def _nav_tree(self, step, level):
153162

154163
new_row = curr.row() + step
155164

156-
# Simple bounds check
165+
# Simple bounds check, logic can be improved to skip hidden items
157166
if 0 <= new_row < model.rowCount(QModelIndex()):
158167
# Check visibility (filter)
159168
while 0 <= new_row < model.rowCount(QModelIndex()):

0 commit comments

Comments
 (0)