1

I am working on an application where several vlc streams (rtsp) are shown and by double-clicking one of them, the stream should be displayed fullscreen. The application is python 3.7 using pyqt5 and vlc-qt.

Code as follows:

import sys
import vlc
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.sizeHint = lambda: QSize(1280, 900)
        self.move(100, 10)

        self.videoFrame = QFrame()
        self.setCentralWidget(self.videoFrame)

        self.vlcInstance = vlc.Instance(['--video-on-top'])
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer.set_mrl("rtsp://xxx.xxx.xxx.xxx", "network-caching=300")
        self.videoPlayer.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer.set_xwindow(self.videoFrame.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer.set_hwnd(self.videoFrame.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer.set_nsobject(int(self.videoFrame.winId()))

        self.videoPlayer.play()
        self.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationName("VLC Test")

    window = MainWindow()
    app.exec_()

When double clicking the video, the following console message appears:

[000001e0a128e630] mmdevice audio output error: cannot initialize COM (error 0x80010106) [000001e0a12c8710] mmdevice audio output error: cannot initialize COM (error 0x80010106) [000001e0a2927420] main vout display error: Failed to set fullscreen

The message "Failed to set fullscreen" appears as soon as I double-click. Does anyone have an idea what the problem might be?

Thanks in advance

hoffmanuel
  • 403
  • 1
  • 5
  • 14
  • This is a reduced code for one stream to simplify things. The video runs perfectly in the window but just fails to set fullscreen – hoffmanuel Sep 12 '18 at 10:51

1 Answers1

4
import sys
import vlc
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.sizeHint = lambda: QSize(1280, 900)
        self.move(100, 10)
        self.mainFrame = QFrame()
        self.setCentralWidget(self.mainFrame)
        t_lay_parent = QHBoxLayout()
        t_lay_parent.setContentsMargins(0, 0, 0, 0)

        self.videoFrame = QFrame()
        self.videoFrame.mouseDoubleClickEvent = self.mouseDoubleClickEvent
        t_lay_parent.addWidget(self.videoFrame)
        self.vlcInstance = vlc.Instance(['--video-on-top'])
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer.video_set_mouse_input(False)
        self.videoPlayer.video_set_key_input(False)
        self.videoPlayer.set_mrl("http://xxx.xxx.xxx.xxx", "network-caching=300")
        self.videoPlayer.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer.set_xwindow(self.videoFrame.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer.set_hwnd(self.videoFrame.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer.set_nsobject(int(self.videoFrame.winId()))

        self.videoPlayer.play()


        self.videoFrame1 = QFrame()
        t_lay_parent.addWidget(self.videoFrame1)
        self.videoFrame1.mouseDoubleClickEvent = self.mouseDoubleClickEvent1
        self.vlcInstance1 = vlc.Instance(['--video-on-top'])
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1.video_set_mouse_input(False)
        self.videoPlayer1.video_set_key_input(False)
        self.videoPlayer1.set_mrl("rtmp://xxx.xxx.xxx.xxx", "network-caching=300")
        self.videoPlayer1.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer1.set_xwindow(self.videoFrame1.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer1.set_hwnd(self.videoFrame1.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer1.set_nsobject(int(self.videoFrame1.winId()))

        self.videoPlayer1.play()

        self.mainFrame.setLayout(t_lay_parent)
        self.show()

    def mouseDoubleClickEvent(self, event):
        if event.button() == Qt.LeftButton:
            if self.windowState() == Qt.WindowNoState:
                self.videoFrame1.hide()
                self.videoFrame.show()
                self.setWindowState(Qt.WindowFullScreen)
            else:
                self.videoFrame1.show()
                self.setWindowState(Qt.WindowNoState)

    def mouseDoubleClickEvent1(self, event):
        if event.button() == Qt.LeftButton:
            if self.windowState() == Qt.WindowNoState:
                self.videoFrame.hide()
                self.videoFrame1.show()
                self.setWindowState(Qt.WindowFullScreen)
            else:
                self.videoFrame.show()
                self.setWindowState(Qt.WindowNoState)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationName("VLC Test")

    window = MainWindow()
    app.exec_()
Degang Guo
  • 475
  • 8
  • 18
  • This works perfectly. Do you have an idea how i can do exactly that if there are two videos in a QGridLayout and the video double clicked shall be fullscreen? – hoffmanuel Sep 13 '18 at 08:10
  • You can wrap video with two QFrame and listen for the mouseDoubleClickEvent. – Degang Guo Sep 13 '18 at 09:17
  • 1
    The mouseDoubleClickEvent does not seem to work inside the QFrame showing the vlc video – hoffmanuel Sep 13 '18 at 09:39