好的,在尝试创建一个非常基本的 MediaPlayer 时遇到一个小问题,只是希望视频在应用程序启动的那一刻开始播放。
#include "mainwindow.h"
#include <QApplication>
#include <QMediaPlayer>
#include <QFileInfo>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QMediaPlayer media;
const QString file = "big_buck_bunny_480p_h264.mov";
QUrl url(QFileInfo(file).absoluteFilePath());
qDebug() << url << endl;
media.setMedia(url);
media.play();
w.show();
return a.exec();
}
目前windows播放音频但播放视频失败,报错
no VideoWindowControl or videoRendererControl, unable to add output node for video data
或者在 linux 中,我从 file:///home/ion/Downloads/big_buck_bunny_1080p_h264.mov 的文件路径获取 我明白了
GStreamer;无法暂停 - “/home/ion/Qt_practice/file:/home/ion/Downloads/big_buck....
错误:“无效的 URI”-“/home/ion/Qt_practice/file:/home/ion/Downloads/big_buck....
据我所知,Windows 的 QMediaPlayer 有问题(是因为我没有先将它传递给 QAbstractVideoSurface 吗?)。但无论如何,如果我想指向 Linux 上的下载位置,正确的路径是什么?另外为什么 Windows 只播放音频是编解码器的东西还是?
甚至尝试将文件复制到程序指向的位置,但即使它在目录中,我预计它仍然会报告无效的 URI。有什么建议吗?
最佳答案
尝试:
QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile("big_buck_bunny_480p_h264.mov"));
QVideoWidget *videoWidget = new QVideoWidget;
w.setCentralWidget(videoWidget); // if w is a QMainWindow
player->setVideoOutput(videoWidget);
player->play();
或者,如果您想知道如何使用 QGraphicsVideoItem 来做到这一点:
QGraphicsView *graphicsView = new QGraphicsView(this);
w.setCentralWidget(graphicsView); // w = QMainWindow
QGraphicsScene *scene = new QGraphicsScene(this);
QMediaPlayer *player = new QMediaPlayer(this);
QGraphicsVideoItem *item = new QGraphicsVideoItem;
graphicsView->setScene(scene);
player->setVideoOutput(item);
graphicsView->scene()->addItem(item);
player->setMedia(QUrl::fromLocalFile("big_buck_bunny_480p_h264.mov"));
player->play();
关于c++ - Qt MediaPlayer 在 linux 中没有播放。 Windows 只能听到声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18593580/