QtMediaPlayer issue

2019-02-25 01:13发布

问题:

I am working with PyQt5 and trying to play a video on my Python application.

I am using Python 3.4.0 and PyQt 5.2.1 and running the application on Ubuntu 14.04, but it id important to make codes cross-platform.

When I run these codes, I get the error of

defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"

My codes:

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import PyQt5.QtMultimedia as M
class Form(QWidget):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.setWindowTitle("IKA Control Panel")
        url= QUrl.fromLocalFile("./some.mp3")
        content= M.QMediaContent(url)
        self.player = M.QMediaPlayer(self)
        self.player.setMedia(content)
        self.player.play()
        self.player.stateChanged.connect( app.quit )
if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)

    screen = Form()
    screen.show()
sys.exit(app.exec_())

How can I solve this problem?

回答1:

Install Qt5 plugins if you are using Ubuntu

sudo apt-get install libqt5multimedia5-plugins


标签: python pyqt5