Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt5 QMediaPlayer ResourceError with seemingly valid QUrl

PyQt5 QMediaPlayer ResourceError with seemingly valid QUrl

Scheduled Pinned Locked Moved Unsolved Language Bindings
4 Posts 2 Posters 3.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    ghidx0
    wrote on last edited by
    #1

    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

    self.mediaPlayer.error.connect(self.handleError)
    

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

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

    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 ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the path you are using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What is the path you are using ?

        G Offline
        G Offline
        ghidx0
        wrote on last edited by
        #3

        @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:

        file:///home/gary/src/opencv/tutorials/samples/video_lit.h264.mp4

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved