fullscreen video

This commit is contained in:
Page Asgardius 2024-08-26 23:26:58 -07:00
parent 1b58342375
commit ea12c10744

View file

@ -2,12 +2,13 @@ import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QWidget, QPushButton, QSlider from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QWidget, QPushButton, QSlider
from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
from PyQt6.QtMultimediaWidgets import QVideoWidget from PyQt6.QtMultimediaWidgets import QVideoWidget
from PyQt6.QtCore import QUrl, Qt from PyQt6.QtCore import QUrl, Qt, QEvent
class VideoPlayer(QMainWindow): class VideoPlayer(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.fswindow = False
self.setWindowTitle("Video Player") self.setWindowTitle("Video Player")
self.setGeometry(100, 100, 640, 480) self.setGeometry(100, 100, 640, 480)
@ -15,6 +16,7 @@ class VideoPlayer(QMainWindow):
self.media_player = QMediaPlayer(None) self.media_player = QMediaPlayer(None)
self.video_widget = QVideoWidget() self.video_widget = QVideoWidget()
self.installEventFilter(self)
self.start_button = QPushButton("Start") self.start_button = QPushButton("Start")
self.start_button.setFixedSize(60, 33) self.start_button.setFixedSize(60, 33)
@ -51,6 +53,34 @@ class VideoPlayer(QMainWindow):
container = QWidget() container = QWidget()
container.setLayout(layout) container.setLayout(layout)
self.setCentralWidget(container) self.setCentralWidget(container)
#self.set_layout()
def set_layout(self):
self.video_widget = QVideoWidget()
self.start_button = QPushButton("Start")
self.start_button.setFixedSize(60, 33)
self.start_button.clicked.connect(self.start_video)
self.pause_button = QPushButton("Pause")
self.pause_button.setFixedSize(60, 33)
self.pause_button.clicked.connect(self.pause_video)
self.stop_button = QPushButton("Stop")
self.stop_button.setFixedSize(60, 33)
self.stop_button.clicked.connect(self.stop_video)
self.slider = QSlider(Qt.Orientation.Horizontal)
self.slider.sliderMoved.connect(self.set_position)
self.media_player.setVideoOutput(self.video_widget)
layout = QVBoxLayout()
controls = QHBoxLayout()
controls.addWidget(self.start_button)
controls.addWidget(self.pause_button)
controls.addWidget(self.stop_button)
layout.addWidget(self.video_widget)
layout.addLayout(controls)
layout.addWidget(self.slider)
container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)
def start_video(self): def start_video(self):
self.media_player.play() self.media_player.play()
@ -62,13 +92,33 @@ class VideoPlayer(QMainWindow):
self.media_player.stop() self.media_player.stop()
def set_position(self, position): def set_position(self, position):
self.media_player.setPosition(position) if not self.fswindow:
self.media_player.setPosition(position)
def position_changed(self, position): def position_changed(self, position):
self.slider.setValue(position) if not self.fswindow:
self.slider.setValue(position)
def duration_changed(self, duration): def duration_changed(self, duration):
self.slider.setRange(0, duration) if not self.fswindow:
self.slider.setRange(0, duration)
def eventFilter(self, obj, event):
if event.type() == QEvent.Type.MouseButtonDblClick:
#print('two left')
if self.fswindow:
self.showNormal()
self.set_layout()
self.fswindow = False
else:
self.showFullScreen()
self.fswindow = True
self.setCentralWidget(self.video_widget)
return True
if __name__ == "__main__": if __name__ == "__main__":