Important: Please read the Qt Code of Conduct -

PyQt5 QMediaPlayer ResourceError with seemingly valid QUrl

  • I've started to build an application in PyQt5, and have run into a little puzzle. After building my QVideoWidget, and hooking the display of a QMediaPlayer to it I've invoked

    Within the QVideoWidget subclass, I've attempted to setMedia to the QMediaPlayer

    content = QMediaContent(url)
    self.mediaPlayer.setMedia(content) # self.mediaPlayer is my QMediaPlayer instance

    I've connected a slot for the QMediaPlayer 's error signal


    And so, after invoking setMedia as described above, I do get a call to self.handlError

        def handleError(self, *args, **kwargs):
            errors = dict({0: "NoError", 1: "ResourceError", 2:"FormatError", 3:"NetworkError",
                           4:"AccessDeniedError", 5:"ServiceMissingError"})
            errorString = self.mediaPlayer.errorString()
            message = "Error: "
            if errorString:
                message += errorString
                error = int(self.mediaPlayer.error())
                message += F'{error} : {errors[error]} with {self.mediaPlayer.currentMedia().canonicalUrl()}'

    In the code above I also investigate the media player itself to inspect its error() results. The error is identical to the error handler slot signal, a PyQt5.QtMultimedia.QMediaPlayer.Error args, which interprets as 1, a ResourceError according to the QMediaPlayer docs QMediaPlayer Error enum

    However, I can investigate the QUrl in the debugger. I place a breakpoint at that last line self.errorLabel.setText(message) and then test the MediaContent's url, which resulted in this ResourceError

    In[8]: filepath = self.mediaPlayer.currentMedia().canonicalUrl().toLocalFile()
    In[9]: os.path.exists(filepath)
    Out[10]: True
    In[10]: os.access(filepath, os.R_OK)
    Out[11]: True
    In[11]: os.access(filepath, os.W_OK)
    Out[12]: True

    I am at a loss as to the cause of the Resource Error. Can anyone point me in the right direction ?

  • Lifetime Qt Champion


    What is the path you are using ?

  • @SGaist
    I create a QUrl from a user argument, which is passed through a validator to confirm that it is valid. The string representation of that url is:


    As in my reference to the debugger session, I can round trip the QUrl, after validating it. I build a Qurl, then I can pull the path
    filepath = self.mediaPlayer.currentMedia().canonicalUrl().toLocalFile()
    and test its existence, as well as my access to the file.

  • Lifetime Qt Champion

    Did you try with a file from another container/format ?

Log in to reply