Important: Please read the Qt Code of Conduct -

QtMultimedia PySide2 Error

  • I am trying to play a simple mp4 file using QtMultimedia in PySide2 but it gives the following error:

    import sys
    from PySide2.QtWidgets import QApplication
    from PySide2.QtCore import QUrl
    from PySide2.QtMultimedia import QMediaPlayer, QMediaPlaylist
    from PySide2.QtMultimediaWidgets import QVideoWidget
    if __name__ == '__main__':
        app = QApplication()
        playlist = QMediaPlaylist()
        player = QMediaPlayer()
        videoWidget = QVideoWidget()


    GStreamer; Unable to pause - "file:demo.mp4"

  • Banned

    Okay first when I ran this code as is -- (switching PySide2 to PyQt5) I get the error:
    TypeError: QApplication(List[str]): not enough arguments

    Fix that error by doing this - app = QApplication([])

    Then I get this error:
    TypeError: setMedia(self, QMediaContent, stream: QIODevice = None): argument 1 has unexpected type 'QUrl'

    So looked into see what you were doing wrong -- and you have not implemented it correctly. Now the below code while it moves into a better direction by handling the various elements correctly it will have an issue if you do not have the appropriate Codec

    From Stackoverflow:
    The error code is rather generic: 0x80040218 VFW_E_CANNOT_RENDER "No combination of filters could be found to render the stream." and the typical cause is that the application cannot decode media feed because it lacks decoding components, such as codec for this video feed is not installed/available.

    I am not going to download a Codec since I am not trying to render a video but here is the adjusted code that utilizes each piece appropriately. Also this was tested with PyQt5 as I do not have PySide2 but they should work the same unless PySide2 has not gotten to this yet. Oh and the error I get when running this in PyQt5 is:
    DirectShowPlayerService::doRender: Unresolved error code 0x80040266 (IDispatch error #102)

    Which I believe is related to the Codec thing as it is a rendering error, although I can double click the file directly and it runs. So maybe its some other disconnection -- or you have to specifically state what Codec you are using. Again this should at least get you moving in the right direction.

    from PySide2.QtCore              import QUrl
    from PySide2.QtWidgets           import QApplication
    from PySide2.QtMultimedia        import QMediaPlayer, QMediaPlaylist, QMediaContent
    from PySide2.QtMultimediaWidgets import QVideoWidget
    class PlayList(QMediaPlaylist):
        def __init__(self):
            UrlMedia = QUrl('demo.mp4')
            BaseUrl  = QUrl('file:/C:/PathTo/Directory/')
            FullMedia = BaseUrl.resolved(UrlMedia)
            self.player = QMediaPlayer()
                self.videoWidget = QVideoWidget()
                print('Error Occurred')
    if __name__ == '__main__':
        MainEvntHndlr = QApplication([])
        MainApp = PlayList()

Log in to reply