|
| 1 | +# Localization Media Player Package |
| 2 | + |
| 3 | +This package contains the UI components responsible for video playback, timeline visualization, and transport controls within the **Localization (Action Spotting)** mode. |
| 4 | + |
| 5 | +It is designed to handle frame-accurate video navigation and visual feedback for temporal events. |
| 6 | + |
| 7 | +## 📂 Directory Structure |
| 8 | + |
| 9 | +```text |
| 10 | +media_player/ |
| 11 | +├── __init__.py # Exports LocCenterPanel and assembles the components |
| 12 | +├── preview.py # Handles the QMediaPlayer and Video Surface |
| 13 | +├── timeline.py # Handles the zoomable Timeline and Event Markers |
| 14 | +└── controls.py # Handles Play/Pause, Seek, and Speed controls |
| 15 | +
|
| 16 | +``` |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## 🧩 Components Detail |
| 21 | + |
| 22 | +### 1. `preview.py` (MediaPreviewWidget) |
| 23 | + |
| 24 | +**Responsibility**: Core media rendering. |
| 25 | + |
| 26 | +* **Video Output**: Wraps `QVideoWidget` to display the video content. |
| 27 | +* **Audio Handling**: Explicitly initializes `QAudioOutput` to ensure compatibility with PyQt6 (prevents black screen issues on some platforms). |
| 28 | +* **State Management**: Emits signals for position, duration, and playback state changes. |
| 29 | +* **API**: |
| 30 | +* `load_video(path)`: Loads a video file. |
| 31 | +* `set_position(ms)`: Seeks to a specific timestamp. |
| 32 | +* `set_playback_rate(rate)`: Adjusts speed (e.g., 0.5x, 2.0x). |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +### 2. `timeline.py` (TimelineWidget) |
| 37 | + |
| 38 | +**Responsibility**: Temporal visualization and navigation. |
| 39 | + |
| 40 | +* **Custom Slider**: Uses `AnnotationSlider` (subclass of `QSlider`) to paint colored markers on the groove representing spotting events. |
| 41 | +* **Zoom Logic**: Supports zooming in/out to increase precision for short clips or view the entire video duration. |
| 42 | +* **Auto-Scrolling**: The timeline automatically follows the playhead during playback. If the user drags the scrollbar manually, auto-scrolling pauses until the playhead catches up. |
| 43 | +* **Interaction**: Dragging the slider handle emits seek requests to the player. |
| 44 | + |
| 45 | +### 3. `controls.py` (PlaybackControlBar) |
| 46 | + |
| 47 | +**Responsibility**: User input for navigation. |
| 48 | + |
| 49 | +* **Transport Buttons**: Play/Pause, Stop. |
| 50 | +* **Seeking**: |
| 51 | +* Fine steps: +/- 1 second. |
| 52 | +* Large steps: +/- 5 seconds. |
| 53 | +* Clip Navigation: Jump to Previous/Next video in the project list. |
| 54 | +* Event Navigation: Jump to Previous/Next annotated event. |
| 55 | + |
| 56 | + |
| 57 | +* **Speed Control**: Buttons to toggle playback speed (0.25x to 4.0x). |
| 58 | + |
| 59 | +### 4. `__init__.py` (LocCenterPanel) |
| 60 | + |
| 61 | +**Responsibility**: Assembly. |
| 62 | + |
| 63 | +* It imports the three widgets above and arranges them in a vertical layout (`QVBoxLayout`). |
| 64 | +* This class is exposed to the main window as the "Center Panel" for the Localization interface. |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## 🔄 Data Flow & Signal Wiring |
| 69 | + |
| 70 | +The wiring between these components is primarily handled by the **LocalizationManager** (Controller), not inside this package. This ensures the View remains decoupled from the Logic. |
| 71 | + |
| 72 | +**Typical Flow:** |
| 73 | + |
| 74 | +1. **User Click**: User clicks "Play" in `PlaybackControlBar`. |
| 75 | +2. **Signal**: `PlaybackControlBar` emits `playPauseRequested`. |
| 76 | +3. **Controller**: `LocalizationManager` receives the signal and calls `MediaPreviewWidget.toggle_play_pause()`. |
| 77 | +4. **Feedback**: `MediaPreviewWidget` updates the video state. |
| 78 | +5. **Sync**: `MediaPreviewWidget` emits `positionChanged`, which is connected to `TimelineWidget.set_position()`, updating the slider UI. |
| 79 | + |
| 80 | +## 🛠 Usage |
| 81 | + |
| 82 | +To use this component in the main application layout: |
| 83 | + |
| 84 | +```python |
| 85 | +from ui.localization.media_player import LocCenterPanel |
| 86 | + |
| 87 | +# Inside the main window setup |
| 88 | +self.center_panel = LocCenterPanel() |
| 89 | +layout.addWidget(self.center_panel) |
| 90 | + |
| 91 | +``` |
| 92 | + |
| 93 | +## ⚠️ Notes |
| 94 | + |
| 95 | +* **PyQt6 Requirement**: This package relies on `PyQt6.QtMultimedia`. Ensure your environment has the necessary codecs installed (e.g., K-Lite Codec Pack on Windows) if you encounter playback issues with specific video formats. |
0 commit comments