0

我创建了一个 QMediaPlayer,将视频地址传递给它,它不会播放。我检查了 mediaStatus 和播放器状态,它们一直保持为 0。基本思想是:

QMediaPlayer player = new QMediaPlayer();
cout << player.mediaStatus(); // should print 1: NoMedia but is 0: UnknownMediaStatus

player.setVideoOutput(some_constructed_video_widget);
cout << player.mediaStatus(); // should print 1: NoMedia but is 0: UnknownMediaStatus

player.setMedia(QUrl::fromLocalFile("path/to/test/video/test.mp4"));
cout << player.mediaStatus(); // should print 2: LoadingMedia but is 0: UnknownMediaStatus

player.play();
cout << player.mediaStatus(); // should print 3: LoadedMedia but is 0: UnknownMediaStatus
                              // and of course, no video gets played

mediaStatus 只是一个枚举:MediaStatus { UnknownMediaStatus, NoMedia, LoadingMedia, LoadedMedia, ..., InvalidMedia }

问题是:

  1. 什么可能导致这个问题以及如何解决这个问题?

  2. QMediaPlayer::mediaStatus() 将返回 QMediaPlayer::UnknownMediaStatus 的所有情况是什么(请确定)?


编辑更多信息:以下是我为以下代码获得的输出。任何人都知道错误消息的含义以及如何解决?

代码:

int main(int argc, char *argv[])
{
    QMediaPlayer * temp = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
    std::cout << "Constructed: " << temp->mediaStatus() << std::endl;
    temp->setMedia(QUrl::fromLocalFile("path/to/video/test.mp4"));
    std::cout << "SetMedia: " << temp->mediaStatus() << std::endl;
    temp->play();
    std::cout << "Play: " << temp->mediaStatus() << std::endl;
-> debug breakpoint here
    ......
}

输出:

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

我使用的是 Mac 10.9 和 Qt 5.3.0,但我认为 mac/qt 版本对这个问题并不重要。

4

0 回答 0