2024-08-17 22:16:12 +02:00
|
|
|
import sys
|
|
|
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QWidget, QPushButton, QSlider
|
|
|
|
from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
|
|
|
|
from PyQt6.QtMultimediaWidgets import QVideoWidget
|
|
|
|
from PyQt6.QtCore import QUrl, Qt
|
|
|
|
|
|
|
|
|
|
|
|
class VideoPlayer(QMainWindow):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.setWindowTitle("Video Player")
|
|
|
|
self.setGeometry(100, 100, 640, 480)
|
|
|
|
#self.showFullScreen()
|
|
|
|
|
|
|
|
self.media_player = QMediaPlayer(None)
|
|
|
|
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)
|
2024-08-18 00:19:47 +02:00
|
|
|
self.media_player.setSource(QUrl("https://video.asgardius.company/download/videos/41bf7df4-8f6c-45e9-96ef-a8dd57c865c8-480.mp4"))
|
2024-08-17 22:16:12 +02:00
|
|
|
self.media_player.positionChanged.connect(self.position_changed)
|
|
|
|
self.media_player.durationChanged.connect(self.duration_changed)
|
|
|
|
self.audio_output = QAudioOutput()
|
|
|
|
self.audio_output.setVolume(100)
|
|
|
|
self.media_player.setAudioOutput(self.audio_output)
|
|
|
|
|
|
|
|
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):
|
|
|
|
self.media_player.play()
|
|
|
|
|
|
|
|
def pause_video(self):
|
|
|
|
self.media_player.pause()
|
|
|
|
|
|
|
|
def stop_video(self):
|
|
|
|
self.media_player.stop()
|
|
|
|
|
|
|
|
def set_position(self, position):
|
|
|
|
self.media_player.setPosition(position)
|
|
|
|
|
|
|
|
def position_changed(self, position):
|
|
|
|
self.slider.setValue(position)
|
|
|
|
|
|
|
|
def duration_changed(self, duration):
|
|
|
|
self.slider.setRange(0, duration)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
video_player = VideoPlayer()
|
|
|
|
video_player.show()
|
|
|
|
sys.exit(app.exec())
|