-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_example_video.py
53 lines (42 loc) · 1.5 KB
/
gui_example_video.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
from PyQt5 import QtWidgets
from example_window_video import Ui_MainWindow
import sys
from PyQt5 import QtCore, QtMultimedia
# The class that handles the application itself
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
# Handle the application display
super(ApplicationWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Connect events (like button presses) to functions
self.ui.button_play.clicked.connect(self.callback_play)
self.ui.button_pause.clicked.connect(self.callback_pause)
self.ui.button_stop.clicked.connect(self.callback_stop)
# Configure the video widget
self.video_player = QtMultimedia.QMediaPlayer(None, QtMultimedia.QMediaPlayer.VideoSurface)
# Load in a file to play
file = QtCore.QDir.current().filePath("video.mp4")
self.video_player.setMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(file)))
self.video_player.setVideoOutput(self.ui.video_widget)
def callback_play(self):
# Start video playback
self.video_player.play()
def callback_pause(self):
# Pause video playback
self.video_player.pause()
def callback_stop(self):
# Pause video playback
self.video_player.stop()
# The "main()" function, like a C program
def main():
print("Loading applicaiton...")
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
print("Application loaded.")
application.show()
sys.exit(app.exec_())
# Provides a start point for out code
if __name__ == "__main__":
main()