Qt 6.11 is out! See what's new in the release
blog
QMediaPlayer stream via QIODevice
General and Desktop
1
Posts
1
Posters
1.6k
Views
1
Watching
-
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 customQIODevice. UnfortunatelyQMediaPlayer::setMediadoes not seem to work with thestreamargument.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::PlayingStateis printed to the stdout, but the video does not play, nor thepositionChangedsignal is emitted. Obviously if I defineOKthe video is played correctly.This page seems to suggest that streaming source is supported with DirectShow.
How can I troubleshoot this issue?