Commit d67754c0 authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere
Browse files

Add of the media snapshot in the media library

parent 128c2325
......@@ -73,7 +73,7 @@ void InputMedia::unlock( LibVLCpp::Media::DataCtx* ctx )
ctx->mutex->unlock();
}
QImage* InputMedia::takeSnapshot( unsigned int width, unsigned int height )
QPixmap* InputMedia::takeSnapshot( unsigned int width, unsigned int height )
{
if ( m_snapshot == NULL )
{
......@@ -89,8 +89,8 @@ QImage* InputMedia::takeSnapshot( unsigned int width, unsigned int height )
char* tmpStr = const_cast<char*>(tmp.fileName().toStdString().c_str());
m_vlcMediaPlayer->takeSnapshot( tmpStr, width, height );
// qDebug() << "done snapshoting";
m_snapshot = new QImage( tmp.fileName() );
// qDebug() << "written to a QImage";
m_snapshot = new QPixmap( tmp.fileName() );
// qDebug() << "written to a QImage";
// m_vlcMediaPlayer->setTime(currentTime);
}
......
......@@ -34,6 +34,8 @@
class InputMedia : public Media
{
Q_OBJECT
public:
InputMedia( const QString& mrl, LibVLCpp::Instance* instance = NULL );
~InputMedia();
......@@ -41,7 +43,7 @@ public:
static void lock( LibVLCpp::Media::DataCtx* dataCtx, void **pp_ret );
static void unlock( LibVLCpp::Media::DataCtx* dataCtx );
QImage* takeSnapshot( unsigned int width, unsigned int heigth );
QPixmap* takeSnapshot( unsigned int width, unsigned int heigth );
/**
* Ask libvlc if the media is currently playing
......@@ -66,9 +68,10 @@ public:
virtual void stop();
private:
QImage* m_snapshot;
QPixmap* m_snapshot;
uchar* m_pixelBuffer;
QImage* m_image;
};
#endif // INPUTMEDIA_H
......@@ -37,6 +37,7 @@ MediaPlayer::MediaPlayer( Media* media, bool playStop /* = true*/ )
// Register the callback
libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, callbacks, this, m_ex );
}
/**
......@@ -56,7 +57,9 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
// case libvlc_MediaPlayerNothingSpecial:
// case libvlc_MediaPlayerOpening:
// case libvlc_MediaPlayerBuffering:
// case libvlc_MediaPlayerPlaying:
case libvlc_MediaPlayerPlaying:
self->emit playing();
break;
// case libvlc_MediaPlayerPaused:
// case libvlc_MediaPlayerStopped:
// case libvlc_MediaPlayerForward:
......
......@@ -61,6 +61,7 @@ namespace LibVLCpp
signals:
void snapshotTaken();
void timeChanged();
void playing();
};
}
......
......@@ -34,7 +34,7 @@
/**
* Generic class for media handling.
*/
class Media
class Media : public QObject
{
public:
virtual ~Media();
......
......@@ -21,18 +21,44 @@
*****************************************************************************/
#include "ListViewMediaItem.h"
#include <QPixmap>
#include <QDebug>
ListViewMediaItem::ListViewMediaItem( QFileInfo* fInfo, ListViewMediaItem::fType fType, QListWidget* parent, int type ) :
QListWidgetItem( parent, type )
{
m_fileInfo = fInfo;
m_fileType = fType;
//TODO : Replace this by snapshot.
setIcon( QIcon( ":/images/images/vlmc.png" ) );
setText( fInfo->baseName() );
QWidget* renderWidget = new QWidget();
m_currentMedia = new InputMedia( "file://" + fInfo->absoluteFilePath() );
m_currentMedia->setupMedia();
m_currentMedia->setDrawable( renderWidget->winId() );
m_currentMedia->play();
connect( m_currentMedia->mediaPlayer(), SIGNAL( playing() ), this, SLOT( setSnapshot() ) );
}
ListViewMediaItem::~ListViewMediaItem()
{
delete m_fileInfo;
}
void ListViewMediaItem::setSnapshot()
{
m_currentMedia->setTime( 50000 );
connect( m_currentMedia->mediaPlayer(), SIGNAL( timeChanged() ), this, SLOT( takeSnapshot() ) );
}
void ListViewMediaItem::takeSnapshot()
{
QPixmap* snapshot = m_currentMedia->takeSnapshot( 32, 32 );
setIcon( QIcon( *snapshot ) );
m_currentMedia->stop();
disconnect( m_currentMedia->mediaPlayer(), SIGNAL( playing() ), this, SLOT( setSnapshot() ) );
disconnect( m_currentMedia->mediaPlayer(), SIGNAL( playing() ), this, SLOT( takeSnapshot() ) );
}
......@@ -23,16 +23,20 @@
#ifndef LISTVIEWMEDIAITEM_H
#define LISTVIEWMEDIAITEM_H
#include <QObject>
#include <QFileInfo>
#include <QListWidgetItem>
#include "InputMedia.h"
/**
* \class ListViewMediaItem
* \brief Items class to use inside MediaListView widget
*/
class ListViewMediaItem : public QListWidgetItem
class ListViewMediaItem : public QObject, public QListWidgetItem
{
Q_OBJECT
public:
/**
* \enum fType
......@@ -82,6 +86,15 @@ private:
* \brief fileType member
*/
ListViewMediaItem::fType m_fileType;
/**
* \Instance of the InputMedia
*/
InputMedia* m_currentMedia;
private slots:
void setSnapshot();
void takeSnapshot();
};
#endif /* !LISTVIEWMEDIAITEM_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment