Cannot play video in Qt

Given below is the code for playing a video. On running it, it says that it could not open file.

#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QFile>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *widget=new QWidget;
    widget->resize(400,300);

    QMediaPlayer *player=new QMediaPlayer;
    QVideoWidget *vw= new QVideoWidget;
    QHBoxLayout *layout=new QHBoxLayout;

    layout->addWidget(vw);
    widget->setLayout(layout);
    player->setVideoOutput(vw);
    QFile file=("1minute.mp4");
    if(!file.open(QIODevice::ReadOnly))
        qDebug()<<"Could not open file";
    player->setMedia(QUrl::fromLocalFile("1minute.mp4"));
    player->play();
    widget->show();
    qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();

    return a.exec();
}

Where am I going wrong?

Answers


Finally found the answer. Added the complete link of the video and it started playing easily. SO the code for the video link should be:

player->setMedia(QUrl::fromLocalFile("C:/Users/Administrator/Desktop/1minute.mp4"));

Need Your Help

Integrating Spiderfier JS into markerClusterer V3 to explode multi-markers with exact same long / lat

google-maps google-maps-api-3 markerclusterer

I am using markerCLusterer V3 on a db file from Filemaker to generate a (semi-live) map of current delivery locations, based off of addresses. Grabbing the lat/long from Google and populating those