, mediaPlayer(0, QMediaPlayer::VideoSurface)
, playButton(0)
, positionSlider(0)
+ , errorLabel(0)
{
QVideoWidget *videoWidget = new QVideoWidget;
connect(positionSlider, SIGNAL(sliderMoved(int)),
this, SLOT(setPosition(int)));
+ errorLabel = new QLabel;
+ errorLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
controlLayout->addWidget(openButton);
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(videoWidget);
layout->addLayout(controlLayout);
+ layout->addWidget(errorLabel);
setLayout(layout);
this, SLOT(mediaStateChanged(QMediaPlayer::State)));
connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64)));
+ connect(&mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError()));
}
VideoPlayer::~VideoPlayer()
void VideoPlayer::openFile()
{
+ errorLabel->setText("");
+
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());
if (!fileName.isEmpty()) {
mediaPlayer.setMedia(QUrl::fromLocalFile(fileName));
-
playButton->setEnabled(true);
}
}
{
mediaPlayer.setPosition(position);
}
+
+void VideoPlayer::handleError()
+{
+ playButton->setEnabled(false);
+ errorLabel->setText("Error: " + mediaPlayer.errorString());
+}