2014-01-25 03:38:38 +08:00
|
|
|
/**
|
2014-03-29 18:49:22 -05:00
|
|
|
* @file
|
|
|
|
|
* @brief Source file for Demo QtPlayer application
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2020-10-18 07:43:37 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "PlayerDemo.h"
|
|
|
|
|
#include "../QtPlayer.h"
|
|
|
|
|
|
2014-01-25 03:38:38 +08:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QFileDialog>
|
2020-08-07 00:49:36 -04:00
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
#include <QMenuBar>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
#include <QApplication>
|
2014-01-25 03:38:38 +08:00
|
|
|
|
|
|
|
|
PlayerDemo::PlayerDemo(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, vbox(new QVBoxLayout(this))
|
|
|
|
|
, menu(new QMenuBar(this))
|
|
|
|
|
, video(new VideoRenderWidget(this))
|
2019-09-21 00:14:32 -04:00
|
|
|
, player(new openshot::QtPlayer(video->GetRenderer()))
|
2014-01-25 03:38:38 +08:00
|
|
|
{
|
2015-02-04 23:56:43 -06:00
|
|
|
setWindowTitle("OpenShot Player");
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2015-02-04 23:56:43 -06:00
|
|
|
menu->setNativeMenuBar(false);
|
2014-01-25 03:38:38 +08:00
|
|
|
|
|
|
|
|
QAction *action = NULL;
|
2015-02-04 23:56:43 -06:00
|
|
|
action = menu->addAction("Choose File");
|
2014-01-25 03:38:38 +08:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(open(bool)));
|
|
|
|
|
|
|
|
|
|
vbox->addWidget(menu, 0);
|
|
|
|
|
vbox->addWidget(video, 1);
|
|
|
|
|
|
|
|
|
|
vbox->setMargin(0);
|
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
resize(600, 480);
|
2014-03-23 01:12:29 -05:00
|
|
|
|
|
|
|
|
// Accept keyboard event
|
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
|
2014-01-25 03:38:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerDemo::~PlayerDemo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 01:10:40 -06:00
|
|
|
void PlayerDemo::closeEvent(QCloseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
// Close window, stop player, and quit
|
|
|
|
|
QWidget *pWin = QApplication::activeWindow();
|
|
|
|
|
pWin->hide();
|
|
|
|
|
player->Stop();
|
|
|
|
|
QApplication::quit();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
void PlayerDemo::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
2015-02-04 23:56:43 -06:00
|
|
|
if (event->key() == Qt::Key_Space || event->key() == Qt::Key_K) {
|
|
|
|
|
|
|
|
|
|
if (player->Mode() == openshot::PLAYBACK_PAUSED)
|
|
|
|
|
{
|
|
|
|
|
// paused, so start playing again
|
2014-03-23 01:12:29 -05:00
|
|
|
player->Play();
|
|
|
|
|
|
2015-02-04 23:56:43 -06:00
|
|
|
}
|
|
|
|
|
else if (player->Mode() == openshot::PLAYBACK_PLAY)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (player->Speed() == 0)
|
|
|
|
|
// already playing, but speed is zero... so just speed up to normal
|
|
|
|
|
player->Speed(1);
|
|
|
|
|
else
|
|
|
|
|
// already playing... so pause
|
|
|
|
|
player->Pause();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
}
|
2015-02-04 23:56:43 -06:00
|
|
|
else if (event->key() == Qt::Key_J) {
|
|
|
|
|
if (player->Speed() - 1 != 0)
|
|
|
|
|
player->Speed(player->Speed() - 1);
|
|
|
|
|
else
|
|
|
|
|
player->Speed(player->Speed() - 2);
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2015-02-04 23:56:43 -06:00
|
|
|
if (player->Mode() == openshot::PLAYBACK_PAUSED)
|
|
|
|
|
player->Play();
|
2014-03-23 01:12:29 -05:00
|
|
|
}
|
2015-02-04 23:56:43 -06:00
|
|
|
else if (event->key() == Qt::Key_L) {
|
|
|
|
|
if (player->Speed() + 1 != 0)
|
|
|
|
|
player->Speed(player->Speed() + 1);
|
|
|
|
|
else
|
|
|
|
|
player->Speed(player->Speed() + 2);
|
|
|
|
|
|
|
|
|
|
if (player->Mode() == openshot::PLAYBACK_PAUSED)
|
2014-03-23 01:12:29 -05:00
|
|
|
player->Play();
|
|
|
|
|
|
|
|
|
|
}
|
2015-02-04 23:56:43 -06:00
|
|
|
else if (event->key() == Qt::Key_Left) {
|
|
|
|
|
if (player->Speed() != 0)
|
|
|
|
|
player->Speed(0);
|
|
|
|
|
player->Seek(player->Position() - 1);
|
|
|
|
|
}
|
|
|
|
|
else if (event->key() == Qt::Key_Right) {
|
|
|
|
|
if (player->Speed() != 0)
|
|
|
|
|
player->Speed(0);
|
|
|
|
|
player->Seek(player->Position() + 1);
|
2014-03-23 01:12:29 -05:00
|
|
|
}
|
2015-06-01 00:20:14 -07:00
|
|
|
else if (event->key() == Qt::Key_Escape) {
|
|
|
|
|
QWidget *pWin = QApplication::activeWindow();
|
|
|
|
|
pWin->hide();
|
|
|
|
|
|
|
|
|
|
player->Stop();
|
|
|
|
|
|
|
|
|
|
QApplication::quit();
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 03:38:38 +08:00
|
|
|
void PlayerDemo::open(bool checked)
|
|
|
|
|
{
|
2015-02-04 23:56:43 -06:00
|
|
|
// Get filename of media files
|
2014-01-25 03:38:38 +08:00
|
|
|
const QString filename = QFileDialog::getOpenFileName(this, "Open Video File");
|
|
|
|
|
if (filename.isEmpty()) return;
|
2015-02-04 23:56:43 -06:00
|
|
|
|
|
|
|
|
// Create FFmpegReader and open file
|
2014-01-25 03:38:38 +08:00
|
|
|
player->SetSource(filename.toStdString());
|
2015-02-04 23:56:43 -06:00
|
|
|
|
|
|
|
|
// Set aspect ratio of widget
|
|
|
|
|
video->SetAspectRatio(player->Reader()->info.display_ratio, player->Reader()->info.pixel_ratio);
|
|
|
|
|
|
|
|
|
|
// Play video
|
2014-01-25 03:38:38 +08:00
|
|
|
player->Play();
|
|
|
|
|
}
|