Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Video Widget load Video



  • Hi, everyone I was loading Video in my QVideoWidget but it didn't load the Video.

        def load_video(self):
            filepath = 'F:/Fun/Songs/12.mp4'
            self.Video_Widget.load(filepath)
            # self.horizontalScrollBar.setMediaObject(self.Video_Widget.mediaObject())
            self.Video_Widget.play()
    

    I take help from this


  • Lifetime Qt Champion

    Hi,

    QVideoWidget has no such method.

    You have a use example in its detailed documentation.



  • @Osama_Billah can you show your error message.

    another example : VideoPlayer



  • This post is deleted!


  • @SGaist While Using the Detail Documentation the following error occur.
    code is below

        def load_video(self):
            player = QMediaPlayer()
            playlist = QMediaPlaylist(player)
            playlist.addMedia(QUrl('F:/Fun/Songs/12.mp4'))
            player.setVideoOutput(self.Video_Widget)
            self.Video_Widget.show()
            playlist.setCurrentIndex(1)
            player.play()
    

    Capture.PNG


  • Lifetime Qt Champion

    Are you using PyQt or PySide2 ?



  • @SGaist PyQt5



  • @SGaist any suggestions. still stuck


  • Lifetime Qt Champion

    Please show some patience and allow 24 hours before bumping your own thread. People answering here are volunteers and may not live in the same timezone as you.

    As for your issue:

    playlist.addMedia(QMediaContent(QUrl.fromLocalFile('F:/Fun/Songs/12.mp4')))
    

    [edit: use fromLocalFile SGaist]



  • @Osama_Billah

    use this
    playlist.addMedia(QUrl.fromLocalFile("F:/Fun/Songs/12.mp4")) ******
    instead of this
    playlist.addMedia(QUrl('F:/Fun/Songs/12.mp4'))

    ****** check file name in single quotes also


  • Lifetime Qt Champion

    @anil_arise The current issue is completely unrelated to quoting or QUrl creation although the use of fromLocalFile is indeed a good idea. addMedia in C++ takes a QMediaContent object which is created thanks to implicit conversion from QUrl. Implicit conversion that does not happen here.



  • @SGaist Hi,I tried this method. through this method file don't crush but still don't display the video.



  • @anil_arise first I use this method it crush. it show an error and the error is below. than I tried @SGaist given method. from that method it didn't crush but still don't disply the video
    Capture.PNG



  • @SGaist @anil_arise thanks. problem Solved. complete code is below

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_VideoWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(733, 505)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.Video_Widget = QVideoWidget(self.centralwidget)
            self.Video_Widget.setGeometry(QtCore.QRect(0, 0, 711, 361))
            self.Video_Widget.setObjectName("Video_Widget")
            self.horizontalScrollBar = QtWidgets.QScrollBar(self.centralwidget)
            self.horizontalScrollBar.setGeometry(QtCore.QRect(0, 380, 721, 16))
            self.horizontalScrollBar.setOrientation(QtCore.Qt.Horizontal)
            self.horizontalScrollBar.setObjectName("horizontalScrollBar")
            self.play = QtWidgets.QPushButton(self.centralwidget)
            self.play.setGeometry(QtCore.QRect(10, 410, 75, 23))
            self.play.setObjectName("play")
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
            self.play.setText(_translate("MainWindow", "play"))
    
    
    from PyQt5.QtMultimediaWidgets import QVideoWidget
    from PyQt5 import QtMultimedia
    
    
    class VideoWindow(QtWidgets.QMainWindow, Ui_VideoWindow):
        def __init__(self, parent=None):
            super(VideoWindow, self).__init__(parent)
            self.setupUi(self)
            self.player = QtMultimedia.QMediaPlayer(self)
            self.player.setVideoOutput(self.Video_Widget)
            self.play.clicked.connect(self.player.play)
            self.playlist = QtMultimedia.QMediaPlaylist(self.player)
            self.player.setPlaylist(self.playlist)
            self.playlist.addMedia(
                QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile("F:/Fun/Songs/12.mp4"))
            )
            self.playlist.setCurrentIndex(0)
    
    
    if __name__ == "__main__":
        import sys
    
        app = QtWidgets.QApplication(sys.argv)
        w = VideoWindow()
        w.show()
        sys.exit(app.exec_())
    

Log in to reply