Question

I'm trying to set-up a QVideoWidget in my app, but i get no audio/video. This is how i create the relevant objects:

m_player = new QMediaPlayer;

m_playlist = new QMediaPlaylist(m_player);
m_playlist->addMedia(QUrl::fromLocalFile("/home/username/Documents/test.mp4"));

m_widgetVideo = new QVideoWidget;
m_player->setVideoOutput(m_widgetVideo);

m_layout = new QHBoxLayout(this);
m_layout->addWidget(m_widgetVideo);
this->setLayout(m_layout);

m_playlist->setCurrentIndex(0);
m_player->play();

All i get is a black screen and no audio nor video. I don't know if I can post the MP4 file here (It's a test file downloaded from YouTube) so if anyone needs info about it, just ask me and I'll get it. Here is the result of running ffprobe on the test files: http://pastebin.com/xpMYbApY

QMediaPlayer->duration();  = -1
QMediaPlayer->supportedMimeTypes(); = ()
QMediaPlayer->errorString() = ""

Also, I have these gstreamer packages:

gstreamer0.10-alsa
gstreamer0.10-ffmpeg
gstreamer0.10-nice
gstreamer0.10-plugins-bad
gstreamer0.10-plugins-bad-multiverse
gstreamer0.10-plugins-base
gstreamer0.10-plugins-base-apps
gstreamer0.10-plugins-good
gstreamer0.10-plugins-ugly
gstreamer0.10-pulseaudio
gstreamer0.10-tools
gstreamer0.10-x

gst-launch-0.10 plays the files perfectly, does this means Qt actually can't find the installed GStreamer codecs?

Was it helpful?

Solution

The problem was the QMediaPlaylist. For some reason, it wasn't working. All I had to do to fix it was:

m_player->setMedia(QUrl::fromLocalFile("path/to/file"));

OTHER TIPS

I know this is a old problem, but 2 years later, I have encountered the same problem. Since I dont have enough rep points to leave a comment, I am posting this as an answer.

This worked for me:

playlist = new QMediaPlaylist;
playlist->addMedia(QUrl("http://example.com/movie1.mp4"));
playlist->addMedia(QUrl("http://example.com/movie2.mp4"));
playlist->addMedia(QUrl("http://example.com/movie3.mp4"));
playlist->setCurrentIndex(1);

player = new QMediaPlayer;
player->setPlaylist(playlist);

videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();

player->play();

Taken right from here

As for the why part in @wingleader's answer, I am guessing

m_playlist = new QMediaPlaylist(m_player);

was logically parenting the playlist to the player but not setting the m_player's playlist property.

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top