PyQt5 QMediaPlayer defaultServiceProvider::requestService(): 找不到服务 - “org.qt-project.qt.mediaplayer”

PyQt5 QMediaPlayer defaultServiceProvider::requestService(): 找不到服务 - “org.qt-project.qt.mediaplayer”

我正在使用 Fedora 28。我正在尝试运行此代码

from PyQt5.QtCore import QCoreApplication, QUrl
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtWidgets import QApplication
import sys
import os


def handle_state_change(state):
    if state == QMediaPlayer.LoadingMedia:
        print('loading')
    if state == QMediaPlayer.LoadedMedia:
        print('loading finished')
        player.play()
    if state == QMediaPlayer.EndOfMedia:
        print('playing finished')
        QCoreApplication.quit()


app = QApplication(sys.argv)

url = QUrl.fromLocalFile(os.path.abspath('./redalert.mp3'))

content = QMediaContent(url)
player = QMediaPlayer()
player.mediaStatusChanged.connect(handle_state_change)
player.setVolume(50)
player.setMedia(content)

app.exec()

但是,它会抛出此错误

Got keys from plugin meta data ("gstreamermediaplayer")
QFactoryLoader::QFactoryLoader() checking directory path "/home/ziggs/PycharmProjects/mozart/venv/bin/mediaservice" ...
Cannot load library /home/ziggs/PycharmProjects/mozart/venv/lib/python3.6/site-packages/PyQt5/Qt/plugins/mediaservice/libgstmediaplayer.so: (/lib64/libQt5MultimediaGstTools.so.5: version `Qt_5_PRIVATE_API' not found (required by /home/ziggs/PycharmProjects/mozart/venv/lib/python3.6/site-packages/PyQt5/Qt/plugins/mediaservice/libgstmediaplayer.so))
QLibraryPrivate::loadPlugin failed on "/home/ziggs/PycharmProjects/mozart/venv/lib/python3.6/site-packages/PyQt5/Qt/plugins/mediaservice/libgstmediaplayer.so" : "Cannot load library /home/ziggs/PycharmProjects/mozart/venv/lib/python3.6/site-packages/PyQt5/Qt/plugins/mediaservice/libgstmediaplayer.so: (/lib64/libQt5MultimediaGstTools.so.5: version `Qt_5_PRIVATE_API' not found (required by /home/ziggs/PycharmProjects/mozart/venv/lib/python3.6/site-packages/PyQt5/Qt/plugins/mediaservice/libgstmediaplayer.so))"
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"

我已经用谷歌搜索了错误并尝试安装相关插件

dnf list qt5-qtmultimedia gstreamer-plugins-ugly
Letzte Prüfung auf abgelaufene Metadaten: vor 0:45:12 am Mo 18 Jun 2018 21:42:00 CEST.
Installierte Pakete
gstreamer-plugins-ugly.x86_64                              0.10.19-27.fc28                               @rpmfusion-free
qt5-qtmultimedia.x86_64                                    5.10.1-1.fc28                                 @anaconda      
Verfügbare Pakete
gstreamer-plugins-ugly.i686                                0.10.19-27.fc28                               rpmfusion-free 
qt5-qtmultimedia.i686                                      5.10.1-1.fc28                                 fedora   

答案1

我对 Qt5.10 也有同样的问题。

我必须回到 Qt5.8 才能让它工作。

相关内容