1

I just installed QT 5 and am trying to run the example for playing video. The code snippet looks like:

QMediaPlayer *player = new QMediaPlayer;

player->setMedia( QUrl::fromLocalFile(fileUrl)  );

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

videoWidget->show();
player->play();

It compiles fine, but when I run it I get the following error:

GStreamer; Unable to play - "file:sample.avi"

Im on Ubuntu 12.04 and have installed all of the extra gstreamer packages in case gstreamer was missing codecs. Ive tried with a few different video formats to no avail. I can play the videos using vlc just fine. Does anyone have any idea why this isnt working?

sibtx13
  • 123
  • 1
  • 6
  • 1
    That "file:sample.avi" looks off, it should be file:// or is it named file:sample.avi? – Nicholas Smith Feb 06 '13 at 12:07
  • The file is called sample.avi. The string "file:sample.avi" is the url that QUrl constructs using the QUrl::fromLocalFile() method after being passed the QString "sample.avi". Just in case, I tried passing in "//sample.avi" to fromLocalFile but get a similar result. So I dont think this is the problem. – sibtx13 Feb 08 '13 at 22:36

1 Answers1

4

It needs absolute path. Try

player->setMedia( QUrl::fromLocalFile(QFileInfo(fileUrl).absoluteFilePath()));
Deepak
  • 470
  • 1
  • 5
  • 15