Qt QGraphicsView not playing any video

。_饼干妹妹 提交于 2021-02-05 07:01:28

问题


I have a very simple QT 5.11.0 application with a graphicsview that i would like to play a video in.

Here is my code, it compiles, loads and displays a blank graphicsview.

#include "Demo_TeleLink.h"


Demo_TeleLink::Demo_TeleLink(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    scene = new QGraphicsScene;
    player = new QMediaPlayer();
    videoItem = new QGraphicsVideoItem;
    newString = "C://Users//Chris//Desktop//Sample1.mp4";

    ui.graphicsView->setScene(scene);

    player->setVideoOutput(videoItem);

    ui.graphicsView->scene()->addItem(videoItem);

    player->setMedia(QUrl(newString));

    ui.graphicsView->fitInView(videoItem);

    player->play();
}

All the required objects are declared in the header as points if needed.

enter image description here


回答1:


The QUrl("/path/of/video") is not a valid url since the scheme file that indicates that it is a local file is not deduced, there are 2 possible solutions to this:

player->setMedia(QUrl::fromLocalFile(newString));

or

player->setMedia(QUrl::fromUserInput(newString));

Maybe the path is not encoded correctly, try using the following code and selecting the video manually

newString = QFileDialog::getOpenFileName(this,
                                         tr("Open Video"),
                                         QDir::homePath(),
                                         tr("Video Files (*.mp4)"));

The OP indicates that it obtains the following error message:

DirectShowPlayerService::doRender: Unresolved error code 0x80040266 (IDispatch error #102)

And according to the QTBUG-52082 reported, the solution is to install the codecs to play mp4 from http://www.codecguide.com/download_kl.htm



来源:https://stackoverflow.com/questions/60495857/qt-qgraphicsview-not-playing-any-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!