Important: Please read the Qt Code of Conduct -

[SOLVED] QMediaPlayer plays local videos, but doesn't play remote videos

  • Windows 7 + Qt 5.1.0 mingw
    QMediaPlayer plays local videos, but doesn't play remote videos. Local video file is the same as remote one. QMediaPlayer sets status QMediaPlayer::InvalidMedia shortly after start.
    Here is the code:
    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QWidget wgt;
    QMediaPlayer *mediaPlayer = new QMediaPlayer(&wgt, QMediaPlayer::StreamPlayback);
    QVideoWidget *videoWidget = new QVideoWidget(&wgt);
    QBoxLayout *layout = new QVBoxLayout;
    mediaPlayer->setMedia(QUrl("")); /* DOESN'T WORK! */
    //mediaPlayer->setMedia(QUrl::fromLocalFile("C:/Users/Yury/Downloads/empty.mp4")); /* WORKS! */
    wgt.resize(640, 480);;
    return app.exec();


  • Moderators

    are you sure you have the QtNetwork module and linked against it?

  • I have

    QT += network

    in my project file. To be completely sure, I've added example to my project. The example works fine.

  • I found that

    returns empty QNetworkConfiguration. My network connection is ok, and running
    QNetworkConfigurationManager ncm;
    foreach (QNetworkConfiguration nc, ncm.allConfigurations(QNetworkConfiguration::Active))
    qDebug() << << nc.identifier();

    gives me two active connections. But trying to set this active connections to my mediaPlayer fails:
    qDebug() << mediaPlayer->currentNetworkConfiguration().identifier(); // empty string!

    The documentation of QMediaPlayer states:
    "QNetworkConfiguration QMediaPlayer::currentNetworkConfiguration() const

    Returns the current network access point in use. If a default contructed QNetworkConfiguration is returned this feature is not available or that none of the current supplied configurations are in use."

    So, I have two possible reasons of my problem.

  • I tried to play different file formats - mov and ts. It works! Perhaps the problem is related to the codecs in my system.
    It takes a lot of time before the video starts, but that's another story )


Log in to reply