-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_player.py
36 lines (29 loc) · 1.3 KB
/
video_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PyQt5.QtWidgets import QVBoxLayout, QWidget
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtCore import QUrl, pyqtSignal
import logging
from datetime import date
logger = logging.getLogger('video_player')
class VideoPlayer(QWidget):
finished = pyqtSignal()
def __init__(self):
super().__init__()
self.setWindowTitle("Видеоплеер")
self.setGeometry(100, 100, 800, 600)
self.layout = QVBoxLayout(self) # type: ignore
self.layout.setContentsMargins(0, 0, 0, 0)
self.video_widget = QVideoWidget(self)
self.layout.addWidget(self.video_widget)
self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
self.media_player.setVideoOutput(self.video_widget)
self.media_player.mediaStatusChanged.connect(self.check_status)
def show_local_video(self, video_path):
try:
self.media_player.setMedia(QMediaContent(QUrl.fromLocalFile(video_path)))
self.media_player.play()
except Exception as e:
raise RuntimeError(f"Error playing video: {video_path}") from e
def check_status(self, status):
if status == QMediaPlayer.EndOfMedia:
self.finished.emit() # type: ignore