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 theQMediaPlayer
content = QMediaContent(url) self.mediaPlayer.setMedia(content) # self.mediaPlayer is my QMediaPlayer instance
I've connected a slot for the
QMediaPlayer
'serror
signalself.mediaPlayer.error.connect(self.handleError)
And so, after invoking
setMedia
as described above, I do get a call toself.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 ResourceErrorIn[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 ?
-
Hi,
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: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. -
Did you try with a file from another container/format ?