Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QtMultimedia PySide2 Error
Pratik Tayshete last edited by
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() playlist.setCurrentIndex(1) player = QMediaPlayer() player.setMedia(QUrl.fromLocalFile("demo.mp4")) player.setPlaylist(playlist) videoWidget = QVideoWidget() player.setVideoOutput(videoWidget) videoWidget.show() player.play() sys.exit(app.exec_())
GStreamer; Unable to pause - "file:demo.mp4"
Denni 0 Banned last edited by Denni 0
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
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): QMediaPlaylist.__init__(self) UrlMedia = QUrl('demo.mp4') BaseUrl = QUrl('file:/C:/PathTo/Directory/') FullMedia = BaseUrl.resolved(UrlMedia) self.addMedia(QMediaContent(FullMedia)) self.setCurrentIndex(1) self.player = QMediaPlayer() self.player.setPlaylist(self) try: self.videoWidget = QVideoWidget() self.player.setVideoOutput(self.videoWidget) self.videoWidget.show() self.player.play() except: print('Error Occurred') if __name__ == '__main__': MainEvntHndlr = QApplication() MainApp = PlayList() MainEvntHndlr.exec()