我正在连接QMediaPlayer::error()信号并尝试播放视频文件:
QMediaPlayer *player = new QMediaPlayer;
QMediaPlaylist *playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl::fromLocalFile("/path/to/file.mp4"));
QVideoWidget *videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->resize(640, 340);
videoWidget->show();
ErrorPrinter *errorPrinter = new ErrorPrinter(player);
QObject::connect(player, SIGNAL(error(QMediaPlayer::Error)), errorPrinter, SLOT(printError(QMediaPlayer::Error)));
player->play();显示了视频小部件,但没有播放任何内容,因此它一定是在某个地方失败了。但是,QMediaPlayer::error()信号永远不会发出!应用程序输出为空,没有断言,play()函数为void (没有表示成功或失败的返回值)和playlist->addMedia always returns true。
我该怎么找出哪里出了问题呢?
发布于 2015-04-17 00:38:22
QMediaPlaylist(player)构造仅设置QObject父级。它不会将播放列表链接到播放器--播放器并不知道播放列表。
所以,你从来没有在播放器上设置过播放列表。您可能还需要将播放列表索引设置为1或0 (?-文档不清楚这一点)。
playlist->setCurrentIndex(1);
player->setPlayList(playlist);
player->play();https://stackoverflow.com/questions/29654457
复制相似问题