QMediaPlayer stream via QIODevice

  • Hi,
    I am trying to play a video using QMediaPlayer streaming functionality. My OS is Windows 7.
    The purpose is to play an encrypted stream, I am planning to do this by writing my custom QIODevice. Unfortunately QMediaPlayer::setMedia does not seem to work with the stream argument.

    My code looks like this:

    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QWidget *widget = new QWidget;
        widget->resize(400, 300);
        QVBoxLayout *layout = new QVBoxLayout;
        QMediaPlayer* player = new QMediaPlayer;
        QVideoWidget* vw = new QVideoWidget;
        QObject::connect(player, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
                         []( QMediaPlayer::Error err)
            qDebug() <<"Error " << err;
        QObject::connect(player, &QMediaPlayer::stateChanged,
                         []( QMediaPlayer::State s)
            qDebug() <<"State " << s;
        QFile file ("Wildlife.wmv");
            qDebug() << "Could not open file";
       #ifdef OK
        player->setMedia(QUrl::fromLocalFile("video.wmv") );
        player->setMedia(QUrl::fromLocalFile("video.wmv"), &file);
        qDebug() << player->availableMetaData() << player->currentMedia().canonicalUrl();
        return app.exec();

    When I run this code, State QMediaPlayer::PlayingState is printed to the stdout, but the video does not play, nor the positionChanged signal is emitted. Obviously if I define OK the video is played correctly.

    This page seems to suggest that streaming source is supported with DirectShow.

    How can I troubleshoot this issue?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.