mirror of
https://invent.kde.org/graphics/okular
synced 2024-11-05 18:34:53 +00:00
03368e06f4
In certain configurations not lugging around a multimedia framework could be preferred.
45 lines
992 B
C++
45 lines
992 B
C++
/*
|
|
SPDX-FileCopyrightText: 2012 Tobias Koening <tokoe@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
#include "snapshottaker.h"
|
|
|
|
#if HAVE_PHONON
|
|
|
|
#include <phonon/mediaobject.h>
|
|
#include <phonon/videowidget.h>
|
|
|
|
#include <QImage>
|
|
|
|
SnapshotTaker::SnapshotTaker(const QUrl &url, QObject *parent)
|
|
: QObject(parent)
|
|
, m_player(new Phonon::VideoPlayer(Phonon::NoCategory, nullptr))
|
|
{
|
|
m_player->load(url);
|
|
m_player->hide();
|
|
|
|
connect(m_player->mediaObject(), &Phonon::MediaObject::stateChanged, this, &SnapshotTaker::stateChanged);
|
|
|
|
m_player->play();
|
|
}
|
|
|
|
SnapshotTaker::~SnapshotTaker()
|
|
{
|
|
m_player->stop();
|
|
delete m_player;
|
|
}
|
|
|
|
void SnapshotTaker::stateChanged(Phonon::State newState, Phonon::State)
|
|
{
|
|
if (newState == Phonon::PlayingState) {
|
|
const QImage image = m_player->videoWidget()->snapshot();
|
|
if (!image.isNull()) {
|
|
Q_EMIT finished(image);
|
|
}
|
|
|
|
m_player->stop();
|
|
deleteLater();
|
|
}
|
|
}
|
|
#endif
|