Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaPlayer stream via QIODevice
Qt 6.11 is out! See what's new in the release blog

QMediaPlayer stream via QIODevice

Scheduled Pinned Locked Moved General and Desktop
multimediamediaplayer
1 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RandomRagingGuy
    wrote on last edited by
    #1

    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;
        });
        
        layout->addWidget(vw);
        widget->setLayout(layout);
        
        player->setVideoOutput(vw);
        
        QFile file ("Wildlife.wmv");
        if(!file.open(QIODevice::ReadOnly))
            qDebug() << "Could not open file";
       #ifdef OK
        player->setMedia(QUrl::fromLocalFile("video.wmv") );
       #else
        player->setMedia(QUrl::fromLocalFile("video.wmv"), &file);
       #endif
        player->play();
        widget->show();
        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?

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved