From b4bb314391b9d363944b8de91ea2c660675fabc6 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Sat, 21 Oct 2017 19:19:28 -0400 Subject: Added some testing code for issues with directories having >10 videos --- src-qt5/core/libLumina/LVideoLabel.cpp | 34 ++++++++++++++++++++++++++++++---- src-qt5/core/libLumina/LVideoLabel.h | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src-qt5/core/libLumina') diff --git a/src-qt5/core/libLumina/LVideoLabel.cpp b/src-qt5/core/libLumina/LVideoLabel.cpp index b90cff66..af23330c 100644 --- a/src-qt5/core/libLumina/LVideoLabel.cpp +++ b/src-qt5/core/libLumina/LVideoLabel.cpp @@ -1,4 +1,5 @@ #include "LVideoLabel.h" +#include LVideoLabel::LVideoLabel(QString file, QWidget *parent) : QLabel(parent) { thumbnail = QPixmap(); @@ -27,13 +28,14 @@ void LVideoLabel::initializeBackend(){ mediaPlayer->setMedia(QUrl::fromLocalFile(filepath)); mediaPlayer->play(); - mediaPlayer->pause(); this->connect(surface, SIGNAL(frameReceived(QPixmap)), this, SLOT(stopVideo(QPixmap))); + this->connect(mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(stateChanged(QMediaPlayer::State))); this->connect(mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(setDuration(QMediaPlayer::MediaStatus))); this->connect(this, SIGNAL(rollOver()), surface, SLOT(switchRollOver())); } + void LVideoLabel::stopVideo(QPixmap pix) { if(!entered) { emit frameReceived(pix); @@ -46,19 +48,42 @@ void LVideoLabel::stopVideo(QPixmap pix) { } } +void LVideoLabel::stateChanged(QMediaPlayer::State state) { + //qDebug() << state; +} + void LVideoLabel::setDuration(QMediaPlayer::MediaStatus status) { - if(status == QMediaPlayer::BufferedMedia) { + //qDebug() << status; + if(status == QMediaPlayer::BufferedMedia && !entered) { //Set duration in the middle to capture the thumbnail mediaPlayer->setPosition(mediaPlayer->duration() / 2); mediaPlayer->play(); - } + }else if(status == QMediaPlayer::EndOfMedia && entered) { //Loop back to the beginning if playback started and at the end of the video + mediaPlayer->setPosition(0); + mediaPlayer->play(); + }else if(status == QMediaPlayer::InvalidMedia){ + mediaPlayer->stop(); + mediaPlayer->play(); + }/*else if(status == QMediaPlayer::LoadingMedia) { + mediaPlayer->pause(); + QTimer timer; + timer.setSingleShot(true); + timer.setInterval(300); + timer.start(); + qDebug() << "Timer Started" << timer.remainingTime(); + while(timer.isActive()) QCoreApplication::processEvents(QEventLoop::AllEvents, 5); + qDebug() << "Timer Finished" << timer.remainingTime(); + mediaPlayer->setPosition(0); + mediaPlayer->play(); + }*/ } void LVideoLabel::resizeEvent(QResizeEvent *event) { - if(!thumbnail.isNull()) + if(!thumbnail.isNull()) //Resize the current pixmap to match the new size this->setPixmap(thumbnail.scaled(this->size(),Qt::IgnoreAspectRatio)); QLabel::resizeEvent(event); } +//Start playing the video from the beginning when the mouse enters the label void LVideoLabel::enterEvent(QEvent *event) { entered=true; emit rollOver(); @@ -67,6 +92,7 @@ void LVideoLabel::enterEvent(QEvent *event) { QWidget::enterEvent(event); } +//Stop the video and set the thumbnail back to the middle of the video when the mouse leaves the label void LVideoLabel::leaveEvent(QEvent *event) { entered=false; mediaPlayer->setPosition(mediaPlayer->duration() / 2); diff --git a/src-qt5/core/libLumina/LVideoLabel.h b/src-qt5/core/libLumina/LVideoLabel.h index 8c544b16..f368c1a8 100644 --- a/src-qt5/core/libLumina/LVideoLabel.h +++ b/src-qt5/core/libLumina/LVideoLabel.h @@ -27,6 +27,7 @@ class LVideoLabel : public QLabel{ void initializeBackend(); void stopVideo(QPixmap); void setDuration(QMediaPlayer::MediaStatus); + void stateChanged(QMediaPlayer::State); private: QMediaPlayer *mediaPlayer; -- cgit