2

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Chris
  • 74
  • 7

1 Answers1

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Hey, thanks for the answer, sadly still a blank window no matter which option i use there. – Chris Mar 02 '20 at 20:29
  • @Chris Do you get an error message in the "Application Output" tab of Qt Creator? – eyllanesc Mar 02 '20 at 20:31
  • This is running in VS – Chris Mar 02 '20 at 20:32
  • @Chris I do not work with VS, maybe there is a tab similar to that information, if not, then open a cmd and run the .exe from there and you will surely get an error message. – eyllanesc Mar 02 '20 at 20:34
  • I swapped the subsystem over to console so i can print debugs, and there is an error code. DirectShowPlayerService::doRender: Unresolved error code 0x80040266 (IDispatch error #102) – Chris Mar 02 '20 at 20:34
  • Both messages only appear at the line player->play(); – Chris Mar 02 '20 at 20:35
  • @Chris Try what I indicated in my update, install K-lite – eyllanesc Mar 02 '20 at 20:42
  • Still the same, thou memory usage went up 20mb while running. – Chris Mar 02 '20 at 20:43
  • @Chris mmm, I don't understand you, have you installed the codecs I indicated? The problem is not Qt but Directshow that does not have the codec installed to play mp4 – eyllanesc Mar 02 '20 at 20:44
  • Awesome, you nailed the issue thank you very much! Its playing now! – Chris Mar 02 '20 at 20:53