From 68ee6a0ec973940eb4f799b00f6518a902cbc4e5 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 26 Aug 2018 20:35:23 +0200 Subject: Implement custom Video player Well, well, well. Due to several unforseen circumstances I ventured into the sources again and implemented a Video player with Qt. Looks very promising so far. There are some bugs to weed out, but I'm getting there... --- videoviewer.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 videoviewer.cpp (limited to 'videoviewer.cpp') diff --git a/videoviewer.cpp b/videoviewer.cpp new file mode 100644 index 0000000..5430e9f --- /dev/null +++ b/videoviewer.cpp @@ -0,0 +1,54 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include +#include +#include + +#include "videoviewer.h" +#include "smglobals.h" + +VideoViewer::VideoViewer(QWidget *parent) : QVideoWidget(parent) { + mPlayer = new QMediaPlayer(this); + mPlayer->setVideoOutput(this); + QMediaPlaylist *playList = new QMediaPlaylist; + mPlayer->setPlaylist(playList); + SmGlobals::instance()->addGlobalWidget(this); +} + +void VideoViewer::keyPressEvent(QKeyEvent *e){ + int keyNum = e->key(); + if(keyNum == Qt::Key_Q){ + close(); + }else if(keyNum == Qt::Key_F){ + setFullScreen(isFullScreen() ? false : true); + }else if(keyNum == Qt::Key_Right){ + mPlayer->setPosition(mPlayer->position() + 5000); + }else if(keyNum == Qt::Key_Left){ + qint64 pos = mPlayer->position(); + mPlayer->setPosition(pos - 5000 < 0 ? 0 : pos - 5000); + }else if(keyNum == Qt::Key_Up){ + mPlayer->setPosition(mPlayer->position() + 60000); + }else if(keyNum == Qt::Key_Down){ + qint64 pos = mPlayer->position(); + mPlayer->setPosition(pos - 60000 < 0 ? 0 : pos - 60000); + }else if(keyNum == Qt::Key_N){ + mPlayer->playlist()->next(); + }else if(keyNum == Qt::Key_P){ + mPlayer->playlist()->previous(); + }else if(keyNum == Qt::Key_M){ + mPlayer->setMuted(mPlayer->isMuted() ? false : true); + } +} + +void VideoViewer::closeEvent(QCloseEvent *e){ + mPlayer->stop(); + SmGlobals::instance()->removeGlobalWidget(this); + deleteLater(); + e->accept(); +} -- cgit v1.2.3-70-g09d2