From 3005f7ab6b19cabf423b85ec7c3845d840c7cb18 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Tue, 3 Oct 2017 18:36:51 -0400 Subject: Reworked the VideoSurface subclass --- src-qt5/desktop-utils/lumina-fileinfo/MainUI.cpp | 37 ++++++++++++---------- src-qt5/desktop-utils/lumina-fileinfo/MainUI.h | 4 ++- .../desktop-utils/lumina-fm/widgets/vidnail.cpp | 6 ++-- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'src-qt5/desktop-utils') diff --git a/src-qt5/desktop-utils/lumina-fileinfo/MainUI.cpp b/src-qt5/desktop-utils/lumina-fileinfo/MainUI.cpp index 4d695ab4..40d2d544 100644 --- a/src-qt5/desktop-utils/lumina-fileinfo/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-fileinfo/MainUI.cpp @@ -23,17 +23,20 @@ MainUI::MainUI() : QDialog(), ui(new Ui::MainUI){ terminate_thread = false; UpdateIcons(); //Set all the icons in the dialog SetupConnections(); - player = new QMediaPlayer(0, QMediaPlayer::VideoSurface); - surface = new LVideoSurface(); + player = new QMediaPlayer(this, QMediaPlayer::VideoSurface); + surface = new LVideoSurface(this); player->setVideoOutput(surface); + player->setMuted(true); + connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(setDuration(QMediaPlayer::MediaStatus))); + connect(surface, SIGNAL(frameReceived(QPixmap)), this, SLOT(stopVideo(QPixmap))); INFO = 0; } MainUI::~MainUI(){ terminate_thread = true; + surface->deleteLater(); + player->deleteLater(); this->close(); - delete surface; - delete player; } //============= @@ -92,15 +95,12 @@ void MainUI::LoadFile(QString path, QString type){ ui->label_file_icon->setPixmap( pix.scaledToHeight(64) ); ui->label_file_size->setText( ui->label_file_size->text()+" ("+QString::number(pix.width())+" x "+QString::number(pix.height())+" px)" ); //qDebug() << " - done with image"; - }/*else if(INFO->isVideo()){ + }else if(INFO->isVideo()){ player->setMedia(QUrl("file://"+INFO->absoluteFilePath())); player->play(); - player->setPosition(player->duration() / 2); - connect(surface, SIGNAL(frameReceived(QImage)), this, SLOT(stopVideo(QImage))); + player->pause(); //Pixmap set when video is loaded in stopVideo - //ui->label_file_icon->setPixmap( QPixmap::fromImage(surface->frameImage()).scaledToHeight(64) ); - //ui->label_file_size->setText( ui->label_file_size->text()+" ("+QString::number(pix.width())+" x "+QString::number(pix.height())+" px)" ); - }*/else{ + }else{ ui->label_file_icon->setPixmap( LXDG::findIcon( INFO->iconfile(), "unknown").pixmap(QSize(64,64)) ); } //Now verify the tab is available in the widget @@ -117,7 +117,7 @@ void MainUI::LoadFile(QString path, QString type){ } //Now load the special XDG desktop info qDebug() << "Check XDG Info:" << type; - qDebug() << INFO->isDesktopFile() << type; + //qDebug() << INFO->isDesktopFile() << type; if(INFO->isDesktopFile() || !type.isEmpty()){ if(INFO->XDG()->type == XDGDesktop::APP){ @@ -310,12 +310,17 @@ void MainUI::getXdgCommand(QString prev){ xdgvaluechanged(); } -/*void MainUI::stopVideo(QImage img) { - static bool flag = true; - if(flag) { player->setPosition(player->duration() / 2); flag = false;} +void MainUI::stopVideo(QPixmap img) { + ui->label_file_icon->setPixmap( img.scaledToHeight(64) ); player->pause(); - ui->label_file_icon->setPixmap( QPixmap::fromImage( img.scaledToHeight(64) )); -}*/ +} + +void MainUI::setDuration(QMediaPlayer::MediaStatus status) { + if(status == QMediaPlayer::BufferedMedia) { + player->setPosition(player->duration() / 2); + player->play(); + } +} void MainUI::on_tool_xdg_getDir_clicked(){ //Find a directory diff --git a/src-qt5/desktop-utils/lumina-fileinfo/MainUI.h b/src-qt5/desktop-utils/lumina-fileinfo/MainUI.h index e1f37425..5ce7b01a 100644 --- a/src-qt5/desktop-utils/lumina-fileinfo/MainUI.h +++ b/src-qt5/desktop-utils/lumina-fileinfo/MainUI.h @@ -37,6 +37,7 @@ private: LFileInfo *INFO; LVideoSurface *surface; QMediaPlayer *player; + bool flag; bool canwrite; bool terminate_thread; //flag for terminating the GetDirSize task @@ -53,7 +54,8 @@ private slots: //UI Buttons void on_push_close_clicked(); void on_push_save_clicked(); - //void stopVideo(QImage); + void stopVideo(QPixmap); + void setDuration(QMediaPlayer::MediaStatus); void getXdgCommand(QString prev = ""); //void on_tool_xdg_getCommand_clicked(QString prev = ""); void on_tool_xdg_getDir_clicked(); diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp index ee76a8dc..d0ecdecf 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp +++ b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp @@ -18,7 +18,7 @@ struct vFrame { public: QString getCodec(); - void goto(int timeInSeconds); + void skipTo(int timeInSeconds); void readVideoFrame(); void getScaledVideoFrame(int scaledSize, vFrame& vFrame); @@ -35,14 +35,12 @@ public: private: - bool readVideoPacket(); bool getVideoPacket(); void scaleVideo(int scaledSize, int& scaledWidth, int& scaledHeight); void createVFrame(AVFrame *vFrame, quint8 *frameBuffer, int width, int height); void calculateDimensions(int size); - void generateThumbnail(const QString& videoFile, ImageWriter& imageWriter, QImage& -image); + void generateThumbnail(const QString& videoFile, ImageWriter& imageWriter, QImage& image); QString getMimeType(const QString& videoFile); QString getExtension(const QString& videoFilename); -- cgit