Trying to play video with qmediaplayer and qvideowidget
Im trying to play a video with a QMediaPlayer and a QVideoWidget. I have just a MainWindow with member variables :
and this in the mainwindow.cpp :
MainWindow::MainWindow(QWidget *parent) :
_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;");
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 ?
Your path is wrong, either use double backslashes to escape the slash properly or do it the Qt way and use forward slashes.
Indeed it works, I thought it was okey with the QUrl isValid returning true.
Thank you !
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 :)