Commit f39d958c authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Add of the thread that will check if the mediaplayer is usable

parent e84db3b0
......@@ -64,8 +64,29 @@ Media::Media( const QString& mrl ) : m_mrl( mrl ), m_snapshot( NULL )
//And now we play the media
m_vlcMediaPlayer = new LibVLCpp::MediaPlayer( m_vlcMedia );
m_isThreadLaunched = false;
m_isThreadFinished = false;
connect(this, SIGNAL(mediaPlayerReady()), this, SLOT(playSlot()));
}
void Media::run()
{
m_vlcMediaPlayer->play();
while ( true )
{
if( m_vlcMediaPlayer->isSeekable() && m_vlcMediaPlayer->getLength() > 0 )
{
emit mediaPlayerReady();
m_isThreadFinished = true;
m_vlcMediaPlayer->stop();
return ;
}
msleep(100);
}
}
Media::~Media()
{
delete m_image;
......@@ -121,6 +142,17 @@ qint64 Media::getLength()
}
void Media::play()
{
if (!m_isThreadLaunched && !m_isThreadFinished)
{
m_isThreadLaunched = true;
start();
}
else if (m_isThreadLaunched && m_isThreadFinished)
m_vlcMediaPlayer->play();
}
void Media::playSlot()
{
m_vlcMediaPlayer->play();
}
......
......@@ -25,6 +25,7 @@
#include <QString>
#include <QImage>
#include <QThread>
#include "VLCMedia.h"
#include "VLCInstance.h"
......@@ -32,8 +33,9 @@
#include "Image.h"
class Media
class Media : public QThread
{
Q_OBJECT
public:
Media( const QString& mrl );
~Media();
......@@ -49,6 +51,8 @@ public:
QImage& getImage();
void play();
virtual void run();
private:
LibVLCpp::Media* m_vlcMedia;
LibVLCpp::MediaPlayer* m_vlcMediaPlayer;
......@@ -57,6 +61,14 @@ private:
QImage* m_snapshot;
uchar* m_pixelBuffer;
QImage* m_image;
bool m_isThreadLaunched;
bool m_isThreadFinished;
private slots:
void playSlot();
signals:
void mediaPlayerReady();
};
#endif // MEDIA_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