PlayerDemo.cpp
Go to the documentation of this file.
/**
* @file
* @brief Source file for Demo QtPlayer application
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @section LICENSE
*
* Copyright (c) 2008-2014 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdio.h"
#include "../../include/QtPlayer.h"
#include "../../include/Qt/PlayerDemo.h"
#include <QMessageBox>
#include <QFileDialog>
PlayerDemo::PlayerDemo(QWidget *parent)
: QWidget(parent)
, vbox(new QVBoxLayout(this))
, menu(new QMenuBar(this))
, video(new VideoRenderWidget(this))
, player(new QtPlayer(video->GetRenderer()))
{
setWindowTitle("OpenShot Player");
menu->setNativeMenuBar(false);
QAction *action = NULL;
action = menu->addAction("Choose File");
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);
// Accept keyboard event
setFocusPolicy(Qt::StrongFocus);
}
PlayerDemo::~PlayerDemo()
{
}
void PlayerDemo::closeEvent(QCloseEvent *event)
{
// Close window, stop player, and quit
QWidget *pWin = QApplication::activeWindow();
pWin->hide();
player->Stop();
QApplication::quit();
}
void PlayerDemo::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Space || event->key() == Qt::Key_K) {
if (player->Mode() == openshot::PLAYBACK_PAUSED)
{
// paused, so start playing again
player->Play();
}
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();
}
}
else if (event->key() == Qt::Key_J) {
cout << "BACKWARD" << player->Speed() - 1 << endl;
if (player->Speed() - 1 != 0)
player->Speed(player->Speed() - 1);
else
player->Speed(player->Speed() - 2);
if (player->Mode() == openshot::PLAYBACK_PAUSED)
player->Play();
}
else if (event->key() == Qt::Key_L) {
cout << "FORWARD" << player->Speed() + 1 << endl;
if (player->Speed() + 1 != 0)
player->Speed(player->Speed() + 1);
else
player->Speed(player->Speed() + 2);
if (player->Mode() == openshot::PLAYBACK_PAUSED)
player->Play();
}
else if (event->key() == Qt::Key_Left) {
cout << "FRAME STEP -1" << endl;
if (player->Speed() != 0)
player->Speed(0);
player->Seek(player->Position() - 1);
}
else if (event->key() == Qt::Key_Right) {
cout << "FRAME STEP +1" << endl;
if (player->Speed() != 0)
player->Speed(0);
player->Seek(player->Position() + 1);
}
else if (event->key() == Qt::Key_Escape) {
cout << "QUIT PLAYER" << endl;
QWidget *pWin = QApplication::activeWindow();
pWin->hide();
player->Stop();
QApplication::quit();
}
event->accept();
QWidget::keyPressEvent(event);
}
void PlayerDemo::open(bool checked)
{
// Get filename of media files
const QString filename = QFileDialog::getOpenFileName(this, "Open Video File");
if (filename.isEmpty()) return;
// Create FFmpegReader and open file
player->SetSource(filename.toStdString());
// Set aspect ratio of widget
video->SetAspectRatio(player->Reader()->info.display_ratio, player->Reader()->info.pixel_ratio);
// Play video
player->Play();
}
openshot::QtPlayer::Seek
void Seek(int64_t new_frame)
Seek to a specific frame in the player.
Definition: QtPlayer.cpp:117
PlayerDemo::PlayerDemo
PlayerDemo(QWidget *parent=0)
Definition: PlayerDemo.cpp:34
openshot::QtPlayer
This class is used to playback a video from a reader.
Definition: QtPlayer.h:46
openshot::QtPlayer::Reader
void Reader(ReaderBase *new_reader)
Set the current reader.
Definition: QtPlayer.cpp:152
VideoRenderWidget
Definition: VideoRenderWidget.h:37
PlayerDemo::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: PlayerDemo.cpp:74
openshot::QtPlayer::Mode
PlaybackMode Mode()
Get the current mode.
Definition: QtPlayer.cpp:101
PlayerDemo::closeEvent
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
Definition: PlayerDemo.cpp:65
openshot::QtPlayer::Stop
void Stop()
Stop the video player and clear the cached frames.
Definition: QtPlayer.cpp:135
openshot::QtPlayer::Pause
void Pause()
Pause the video.
Definition: QtPlayer.cpp:106
openshot::PLAYBACK_PAUSED
Pause the video (holding the last displayed frame)
Definition: PlayerBase.h:46
openshot::QtPlayer::Speed
float Speed()
Get the Playback speed.
Definition: QtPlayer.cpp:178
PlayerDemo::~PlayerDemo
~PlayerDemo()
Definition: PlayerDemo.cpp:61
openshot::QtPlayer::Position
int Position()
Get the current frame number being played.
Definition: QtPlayer.cpp:112
openshot::QtPlayer::Play
void Play()
Play the video.
Definition: QtPlayer.cpp:82
openshot::QtPlayer::SetSource
void SetSource(const std::string &source)
Set the source URL/path of this player (which will create an internal Reader)
Definition: QtPlayer.cpp:62
VideoRenderWidget::SetAspectRatio
void SetAspectRatio(openshot::Fraction new_aspect_ratio, openshot::Fraction new_pixel_ratio)
Definition: VideoRenderWidget.cpp:58
openshot::PLAYBACK_PLAY
Play the video normally.
Definition: PlayerBase.h:45