@@ -7,10 +7,10 @@ VideoTestWidget::VideoTestWidget(QWidget *parent) :
77 this ->setMinimumSize (400 , 400 );
88 this ->setMaximumSize (800 , 800 );
99 mediaPlayer = new QMediaPlayer (NULL , QMediaPlayer::VideoSurface);
10- videoWidget = new QVideoWidget;
10+ videoWidget = new QVideoWidget () ;
1111 videoWidget->setObjectName (" videoPlayer" );
1212
13- playButton = new QPushButton;
13+ playButton = new QPushButton () ;
1414 playButton->setIcon (style ()->standardIcon (QStyle::SP_MediaPlay));
1515 playButton->setEnabled (false );
1616 connect (playButton, SIGNAL (clicked ()), this , SLOT (play ()));
@@ -32,27 +32,33 @@ VideoTestWidget::VideoTestWidget(QWidget *parent) :
3232
3333 QWidget *centralWidget = new QWidget ();
3434 this ->setCentralWidget (centralWidget);
35- QVBoxLayout *centralWidgetLayout = new QVBoxLayout;
35+ QVBoxLayout *centralWidgetLayout = new QVBoxLayout () ;
3636 centralWidget->setLayout (centralWidgetLayout);
3737
3838 centralWidgetLayout->addWidget (videoWidget);
39- QHBoxLayout *controlsLayout = new QHBoxLayout;
39+ QHBoxLayout *controlsLayout = new QHBoxLayout () ;
4040 centralWidgetLayout->addLayout (controlsLayout);
4141 controlsLayout->addWidget (playButton);
4242 controlsLayout->addWidget (positionSlider);
4343 controlsLayout->addWidget (volumeSlider);
4444
45- QString fileName = QDir::currentPath () + " /TestData/TestVideo.ogv" ;
45+ QString videoPath (tests::testDataFolder.c_str ());
46+ if (!videoPath.isEmpty ()){
47+ if (!videoPath.endsWith (" /" ))
48+ videoPath.append (" /" );
49+ videoPath += " TestVideo.ogv" ;
50+ }
4651
47- if (!fileName.isEmpty ()) {
48- mediaPlayer->setMedia (QUrl::fromLocalFile (fileName));
52+ QUrl videoUrl = QUrl::fromLocalFile (videoPath);
53+ if (!videoUrl.isEmpty () && videoUrl.isValid ()) {
54+ mediaPlayer->setMedia (videoUrl);
4955 durationChanged (mediaPlayer->duration ());
5056 positionChanged (mediaPlayer->position ());
5157 volumeChanged (mediaPlayer->volume ());
5258 playButton->setEnabled (true );
59+ QSize resolution = mediaPlayer->media ().canonicalResource ().resolution ();
60+ this ->setGeometry (0 ,0 , resolution.width (), resolution.height ());
5361 }
54- QSize resolution = mediaPlayer->media ().canonicalResource ().resolution ();
55- this ->setGeometry (0 ,0 , resolution.width (), resolution.height ());
5662
5763 mediaPlayer->setVideoOutput (this ->videoWidget );
5864}
0 commit comments