I created a media player application using python-vlc
and PyQt5
, quite similar to this qtvlc code.
A minimal reproducible code is shown as follows:
class Player(QMainWindow):
"""A simple Media Player using VLC and Qt
"""
def __init__(self, master=None):
QMainWindow.__init__(self, master)
self.setWindowTitle("Media Player")
# creating a basic vlc instance
self.instance = vlc.Instance()
# creating an empty vlc media player
self.mediaplayer = self.instance.media_player_new()
self.createUI()
self.isPaused = False
def createUI(self):
"""Set up the user interface, signals & slots
"""
self.widget = QWidget(self)
self.setCentralWidget(self.widget)
self.videoframe = QFrame()
self.videoframe.setAutoFillBackground(True)
pixmap = QtGui.QPixmap()
pixmap.load("path to transparent_image.png")
self.my_label = QLabel(self)
self.my_label.setPixmap(pixmap)
self.my_label.setGeometry(300, 250, 100, 100)
self.my_label.setFrameStyle(QFrame.NoFrame)
self.my_label.setAttribute(Qt.WA_TranslucentBackground)
self.vboxlayout = QVBoxLayout()
self.vboxlayout.addWidget(self.videoframe)
self.widget.setLayout(self.vboxlayout)
self.media = self.instance.media_new("path to video file")
# put the media in the media player
self.mediaplayer.set_media(self.media)
# the media player has to be 'connected' to the QFrame
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if sys.platform.startswith('linux'): # for Linux using the X Server
self.mediaplayer.set_xwindow(self.videoframe.winId())
elif sys.platform == "win32": # for Windows
self.mediaplayer.set_hwnd(self.videoframe.winId())
elif sys.platform == "darwin": # for MacOS
self.mediaplayer.set_nsobject(self.videoframe.winId())
self.mediaplayer.play()
if __name__ == "__main__":
app = QApplication(sys.argv)
player = Player()
player.show()
player.resize(640, 480)
sys.exit(app.exec_())
Once I run the code, I can see that the transparent image is drawn on top of the video but the image instead of showing the background video through it continues to show the portion of the QFrame
as its background. Can anyone help me with getting around this issue?