2012-08-30 22:53:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2012 by Tobias Koening <tokoe@kde.org> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2012-06-29 09:16:28 +00:00
|
|
|
#include "snapshottaker.h"
|
|
|
|
|
|
|
|
#include <phonon/mediaobject.h>
|
|
|
|
#include <phonon/videowidget.h>
|
|
|
|
|
2018-08-17 18:05:01 +00:00
|
|
|
#include <QImage>
|
2012-06-29 09:16:28 +00:00
|
|
|
|
2016-07-24 20:40:20 +00:00
|
|
|
SnapshotTaker::SnapshotTaker(const QUrl &url, QObject *parent )
|
2012-06-29 09:16:28 +00:00
|
|
|
: QObject( parent )
|
2017-09-05 21:27:18 +00:00
|
|
|
, m_player( new Phonon::VideoPlayer( Phonon::NoCategory, nullptr ) )
|
2012-06-29 09:16:28 +00:00
|
|
|
{
|
|
|
|
m_player->load( url );
|
|
|
|
m_player->hide();
|
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
connect(m_player->mediaObject(), &Phonon::MediaObject::stateChanged,
|
|
|
|
this, &SnapshotTaker::stateChanged);
|
2012-06-29 09:16:28 +00:00
|
|
|
|
|
|
|
m_player->play();
|
|
|
|
}
|
|
|
|
|
2012-09-28 08:11:13 +00:00
|
|
|
SnapshotTaker::~SnapshotTaker()
|
|
|
|
{
|
|
|
|
m_player->stop();
|
|
|
|
delete m_player;
|
|
|
|
}
|
|
|
|
|
2012-06-29 09:16:28 +00:00
|
|
|
void SnapshotTaker::stateChanged(Phonon::State newState, Phonon::State)
|
|
|
|
{
|
|
|
|
if (newState == Phonon::PlayingState) {
|
|
|
|
const QImage image = m_player->videoWidget()->snapshot();
|
|
|
|
if (!image.isNull())
|
|
|
|
emit finished( image );
|
|
|
|
|
|
|
|
m_player->stop();
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
}
|