The QMediaPlayer object does not have a valid service on Ubuntu 16.04
Unsolved
General and Desktop
-
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() layout.addWidget(video_widget) self.setLayout(layout) self.media_player.setVideoOutput(video_widget) self.media_player.error.connect(self.handle_error) def open_file(self, file_name): self.media_player.setMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(file_name))) def play(self, file_path): self.open_file(file_path) self.media_player.play() def handle_error(self): print(self.media_player.errorString()) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) player = VideoPlayer() player.resize(320, 240) player.show() player.play(video_path) sys.exit(app.exec_())
Has anyone experienced the same problem?