我创建了一个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}
问题是:
可能导致此问题的原因以及如何解决此问题?
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版本对此问题很重要。