The QMediaPlayer object does not have a valid service on Ubuntu 16.04

  • Hi all,

    I'm trying to create a simple video player using Python3.5 / Qt5 / PySide2 (5.11.2) on Ubuntu 16.04, but I'm getting an error when trying to play the video: The QMediaPlayer object does not have a valid service.

    I found that this can be caused by missing some gstreamer library, so I tried to install some gstreamer related libraries, but that didn't help:

    • libgstreamer1.0-0
    • libgstreamer1.0-dev
    • libgstreamer-plugins-base1.0-dev
    • libgstreamer-plugins-good1.0-dev
    • gstreamer1.0-plugins-base
    • gstreamer1.0-plugins-good
    • gstreamer1.0-tools
    • libqt5gstreamer-1.0-0
    • libqt5gstreamer-dev
    • qt5gstreamer-dbg
    • qtgstreamer-plugins-qt5

    Here is the code I'm trying to run:

    import sys
    from PySide2 import QtCore, QtWidgets, QtMultimedia, QtMultimediaWidgets
    video_path = "some/path/to/video.mp4"
    class VideoPlayer(QtWidgets.QWidget):
        def __init__(self, parent=None):
            super(VideoPlayer, self).__init__(parent)
            self.media_player = QtMultimedia.QMediaPlayer(None, QtMultimedia.QMediaPlayer.VideoSurface)
            video_widget = QtMultimediaWidgets.QVideoWidget()
            layout = QtWidgets.QVBoxLayout()
        def open_file(self, file_name):
        def play(self, file_path):
        def handle_error(self):
    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        player = VideoPlayer()
        player.resize(320, 240)

    Has anyone experienced the same problem?

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.