Unsolved Trying to play video with qmediaplayer and qvideowidget
-
Hi,
Im trying to play a video with a QMediaPlayer and a QVideoWidget. I have just a MainWindow with member variables :
QVideoWidget *_video;
QMediaPlaplyer *_player;
QMediaPlaylist *_playlist;and this in the mainwindow.cpp :
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);_player = new QMediaPlayer(this); _video = new QVideoWidget(this); _playlist = new QMediaPlaylist(this); QUrl url = QUrl::fromLocalFile("C:\Users\*****\Downloads\Despicable Me (2010) [1080p]\test.mp4"); _playlist->addMedia(url); std::cout << "C'est valide " << url.isValid() << std::endl; _playlist->setCurrentIndex(1); _player->setPlaylist(_playlist); _player->setVideoOutput(_video); _video->show(); _player->play();
// _test = new QWidget(this);
// _test->setStyleSheet("background: blue;");
setCentralWidget(_video);
}When i try to display a simple QWidget _test with a blue background it displays it, but it doesnt work with the QVideoWidget. The url is valid and I just want to play the video.
Does anyone have a suggestion ?
-
Hi,
Your path is wrong, either use double backslashes to escape the slash properly or do it the Qt way and use forward slashes.
-
-
A valid URL doesn't mean that it points to something valid ;)
You're welcome !
Since you have it working now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)