<html><head></head><body>Olivier, this change does not seem to follow our author naming policies ☹️<br><br><div class="gmail_quote">Le 31 janvier 2019 00:29:20 GMT+02:00, Saveliy <git@videolan.org> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">vlc/python | branch: master | Saveliy <saveliy.m.yusufov@gmail.com> | Wed Dec 26 12:54:26 2018 -0500| [60aa8ea5763a3f93829b5bbaabb6c1011994b2a2] | committer: Olivier Aubert<br><br>Add python-qt5 example<br><br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><a href="http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=60aa8ea5763a3f93829b5bbaabb6c1011994b2a2">http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=60aa8ea5763a3f93829b5bbaabb6c1011994b2a2</a><br></blockquote><hr> examples/pyqt5vlc.py | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++<br> 1 file changed, 205 insertions(+)<br><br>diff --git a/examples/pyqt5vlc.py b/examples/pyqt5vlc.py<br>new file mode 100644<br>index 0000000..abf0cf2<br>--- /dev/null<br>+++ b/examples/pyqt5vlc.py<br>@@ -0,0 +1,205 @@<br>+"""<br>+A simple example for VLC python bindings using PyQt5.<br>+<br>+Author: Saveliy Yusufov, Columbia University, sy2685@columbia.edu<br>+Date: 25 December 2018<br>+"""<br>+<br>+import platform<br>+import os<br>+import sys<br>+<br>+from PyQt5 import QtWidgets, QtGui, QtCore<br>+import vlc<br>+<br>+class Player(QtWidgets.QMainWindow):<br>+ """A simple Media Player using VLC and Qt<br>+ """<br>+<br>+ def __init__(self, master=None):<br>+ QtWidgets.QMainWindow.__init__(self, master)<br>+ self.setWindowTitle("Media Player")<br>+<br>+ # Create a basic vlc instance<br>+ self.instance = vlc.Instance()<br>+<br>+ self.media = None<br>+<br>+ # Create an empty vlc media player<br>+ self.mediaplayer = self.instance.media_player_new()<br>+<br>+ self.create_ui()<br>+ self.is_paused = False<br>+<br>+ def create_ui(self):<br>+ """Set up the user interface, signals & slots<br>+ """<br>+ self.widget = QtWidgets.QWidget(self)<br>+ self.setCentralWidget(self.widget)<br>+<br>+ # In this widget, the video will be drawn<br>+ if platform.system() == "Darwin": # for MacOS<br>+ self.videoframe = QtWidgets.QMacCocoaViewContainer(0)<br>+ else:<br>+ self.videoframe = QtWidgets.QFrame()<br>+<br>+ self.palette = self.videoframe.palette()<br>+ self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0))<br>+ self.videoframe.setPalette(self.palette)<br>+ self.videoframe.setAutoFillBackground(True)<br>+<br>+ self.positionslider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)<br>+ self.positionslider.setToolTip("Position")<br>+ self.positionslider.setMaximum(1000)<br>+ self.positionslider.sliderMoved.connect(self.set_position)<br>+ self.positionslider.sliderPressed.connect(self.set_position)<br>+<br>+ self.hbuttonbox = QtWidgets.QHBoxLayout()<br>+ self.playbutton = QtWidgets.QPushButton("Play")<br>+ self.hbuttonbox.addWidget(self.playbutton)<br>+ self.playbutton.clicked.connect(self.play_pause)<br>+<br>+ self.stopbutton = QtWidgets.QPushButton("Stop")<br>+ self.hbuttonbox.addWidget(self.stopbutton)<br>+ self.stopbutton.clicked.connect(self.stop)<br>+<br>+ self.hbuttonbox.addStretch(1)<br>+ self.volumeslider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)<br>+ self.volumeslider.setMaximum(100)<br>+ self.volumeslider.setValue(self.mediaplayer.audio_get_volume())<br>+ self.volumeslider.setToolTip("Volume")<br>+ self.hbuttonbox.addWidget(self.volumeslider)<br>+ self.volumeslider.valueChanged.connect(self.set_volume)<br>+<br>+ self.vboxlayout = QtWidgets.QVBoxLayout()<br>+ self.vboxlayout.addWidget(self.videoframe)<br>+ self.vboxlayout.addWidget(self.positionslider)<br>+ self.vboxlayout.addLayout(self.hbuttonbox)<br>+<br>+ self.widget.setLayout(self.vboxlayout)<br>+<br>+ menu_bar = self.menuBar()<br>+<br>+ # File menu<br>+ file_menu = menu_bar.addMenu("File")<br>+<br>+ # Add actions to file menu<br>+ open_action = QtWidgets.QAction("Load Video", self)<br>+ close_action = QtWidgets.QAction("Close App", self)<br>+ file_menu.addAction(open_action)<br>+ file_menu.addAction(close_action)<br>+<br>+ open_action.triggered.connect(self.open_file)<br>+ close_action.triggered.connect(sys.exit)<br>+<br>+ self.timer = QtCore.QTimer(self)<br>+ self.timer.setInterval(100)<br>+ self.timer.timeout.connect(self.update_ui)<br>+<br>+ def play_pause(self):<br>+ """Toggle play/pause status<br>+ """<br>+ if self.mediaplayer.is_playing():<br>+ self.mediaplayer.pause()<br>+ self.playbutton.setText("Play")<br>+ self.is_paused = True<br>+ self.timer.stop()<br>+ else:<br>+ if self.mediaplayer.play() == -1:<br>+ self.open_file()<br>+ return<br>+<br>+ self.mediaplayer.play()<br>+ self.playbutton.setText("Pause")<br>+ self.timer.start()<br>+ self.is_paused = False<br>+<br>+ def stop(self):<br>+ """Stop player<br>+ """<br>+ self.mediaplayer.stop()<br>+ self.playbutton.setText("Play")<br>+<br>+ def open_file(self):<br>+ """Open a media file in a MediaPlayer<br>+ """<br>+<br>+ dialog_txt = "Choose Media File"<br>+ filename = QtWidgets.QFileDialog.getOpenFileName(self, dialog_txt, os.path.expanduser('~'))<br>+ if not filename:<br>+ return<br>+<br>+ # getOpenFileName returns a tuple, so use only the actual file name<br>+ self.media = self.instance.media_new(filename[0])<br>+<br>+ # Put the media in the media player<br>+ self.mediaplayer.set_media(self.media)<br>+<br>+ # Parse the metadata of the file<br>+ self.media.parse()<br>+<br>+ # Set the title of the track as window title<br>+ self.setWindowTitle(self.media.get_meta(0))<br>+<br>+ # The media player has to be 'connected' to the QFrame (otherwise the<br>+ # video would be displayed in it's own window). This is platform<br>+ # specific, so we must give the ID of the QFrame (or similar object) to<br>+ # vlc. Different platforms have different functions for this<br>+ if platform.system() == "Linux": # for Linux using the X Server<br>+ self.mediaplayer.set_xwindow(int(self.videoframe.winId()))<br>+ elif platform.system() == "Windows": # for Windows<br>+ self.mediaplayer.set_hwnd(int(self.videoframe.winId()))<br>+ elif platform.system() == "Darwin": # for MacOS<br>+ self.mediaplayer.set_nsobject(int(self.videoframe.winId()))<br>+<br>+ self.play_pause()<br>+<br>+ def set_volume(self, volume):<br>+ """Set the volume<br>+ """<br>+ self.mediaplayer.audio_set_volume(volume)<br>+<br>+ def set_position(self):<br>+ """Set the movie position according to the position slider.<br>+ """<br>+<br>+ # The vlc MediaPlayer needs a float value between 0 and 1, Qt uses<br>+ # integer variables, so you need a factor; the higher the factor, the<br>+ # more precise are the results (1000 should suffice).<br>+<br>+ # Set the media position to where the slider was dragged<br>+ self.timer.stop()<br>+ pos = self.positionslider.value()<br>+ self.mediaplayer.set_position(pos / 1000.0)<br>+ self.timer.start()<br>+<br>+ def update_ui(self):<br>+ """Updates the user interface"""<br>+<br>+ # Set the slider's position to its corresponding media position<br>+ # Note that the setValue function only takes values of type int,<br>+ # so we must first convert the corresponding media position.<br>+ media_pos = int(self.mediaplayer.get_position() * 1000)<br>+ self.positionslider.setValue(media_pos)<br>+<br>+ # No need to call this function if nothing is played<br>+ if not self.mediaplayer.is_playing():<br>+ self.timer.stop()<br>+<br>+ # After the video finished, the play button stills shows "Pause",<br>+ # which is not the desired behavior of a media player.<br>+ # This fixes that "bug".<br>+ if not self.is_paused:<br>+ self.stop()<br>+<br>+def main():<br>+ """Entry point for our simple vlc player<br>+ """<br>+ app = QtWidgets.QApplication(sys.argv)<br>+ player = Player()<br>+ player.show()<br>+ player.resize(640, 480)<br>+ sys.exit(app.exec_())<br>+<br>+if __name__ == "__main__":<br>+ main()<hr>vlc-commits mailing list<br>vlc-commits@videolan.org<br><a href="https://mailman.videolan.org/listinfo/vlc-commits">https://mailman.videolan.org/listinfo/vlc-commits</a><br></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>