Commit f958aebb authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen
Browse files

Corrected EndReached for preview

More stuff on Media List... but seems like it will soon disappear :o)
parent 8f04cd20
......@@ -26,6 +26,7 @@
#include "vlc/vlc.h"
#include "VLCpp.hpp"
//TODO: this would be better as an inline function...
#define CheckVlcppException(ex) (ex.checkThrow(__FILE__, __LINE__))
namespace LibVLCpp
......
......@@ -30,9 +30,20 @@ MediaList::~MediaList()
}
MediaList::Locker::Locker( MediaList::internalPtr mediaList ) : m_mediaList( mediaList )
{
libvlc_media_list_lock( mediaList );
}
MediaList::Locker::~Locker()
{
libvlc_media_list_unlock( m_mediaList );
}
void MediaList::initWatchedEvents()
{
libvlc_event_attach( m_eventManager, libvlc_MediaListItemAdded, callbacks, this, m_exception );
libvlc_event_attach( m_eventManager, libvlc_MediaListItemAdded, callbacks, this, m_exception );
CheckVlcppException( m_exception );
}
void MediaList::callbacks( const libvlc_event_t* event, void* ptr)
......@@ -40,9 +51,9 @@ void MediaList::callbacks( const libvlc_event_t* event, void* ptr)
MediaList* self = reinterpret_cast< MediaList* >( ptr );
switch ( event->type )
{
case libvlc_MediaListItemAdded:
qDebug() << "Media list added";
break ;
case libvlc_MediaListPlayerStopped:
qDebug() << "Playlist stopped";
break;
default:
break ;
}
......@@ -62,12 +73,43 @@ void MediaList::setMediaPlayer( MediaPlayer* mp )
CheckVlcppException(m_exception);
}
MediaList::Locker::Locker( MediaList::internalPtr mediaList ) : m_mediaList( mediaList )
int MediaList::count()
{
libvlc_media_list_lock( mediaList );
MediaList::Locker lockMediaList( m_internalPtr );
int nbElems = libvlc_media_list_count( m_internalPtr, m_exception );
CheckVlcppException( m_exception );
return nbElems;
}
MediaList::Locker::~Locker()
void MediaList::clear()
{
libvlc_media_list_unlock( m_mediaList );
MediaList::Locker lockMediaList( m_internalPtr );
//Don't call MediaList::count() since it holds a lock that's already locked just above !
int nbElems = libvlc_media_list_count( m_internalPtr, m_exception );
CheckVlcppException( m_exception );
for (int i; i < nbElems; ++i)
{
libvlc_media_list_remove_index( m_internalPtr, i, m_exception );
CheckVlcppException( m_exception );
}
}
void MediaList::play()
{
libvlc_media_list_player_play( m_listPlayer, m_exception );
CheckVlcppException( m_exception );
}
void MediaList::pause()
{
libvlc_media_list_player_pause( m_listPlayer, m_exception );
CheckVlcppException( m_exception );
}
void MediaList::stop()
{
libvlc_media_list_player_stop( m_listPlayer, m_exception );
CheckVlcppException( m_exception );
}
......@@ -22,8 +22,13 @@ namespace LibVLCpp
MediaList();
~MediaList();
void addMedia( Media* media );
void addMedia( LibVLCpp::Media* media );
void setMediaPlayer( MediaPlayer* mp );
int count();
void clear();
void play();
void pause();
void stop();
static void callbacks( const libvlc_event_t* event, void* self );
private:
void initWatchedEvents();
......
......@@ -44,10 +44,15 @@ PreviewWidget::PreviewWidget( QWidget *parent ) :
this, SLOT( seekSliderMoved(int) ) );
m_mediaPlayer = new LibVLCpp::MediaPlayer();
m_mediaPlayer->setDrawable( m_ui->clipRenderWidget->winId() );
// m_mediaList = new LibVLCpp::MediaList();
// m_mediaList->setMediaPlayer( m_mediaPlayer );
}
PreviewWidget::~PreviewWidget()
{
delete m_mediaPlayer;
delete m_ui;
}
......@@ -72,9 +77,8 @@ void PreviewWidget::dropEvent( QDropEvent* event )
{
Clip* clip = Library::getInstance()->getClip( event->mimeData()->text() );
m_mediaPlayer->setMedia( clip->getVLCMedia() );
clip->flushParameters();
m_mediaPlayer->setDrawable( m_ui->clipRenderWidget->winId() );
m_mediaPlayer->setMedia( clip->getVLCMedia() );
//FIXME Connecting endReached to pause to change icon of playpause button
// this might not work as it works now later!
......@@ -94,6 +98,10 @@ void PreviewWidget::dropEvent( QDropEvent* event )
SIGNAL( positionChanged() ),
this,
SLOT( positionChanged() ) );
connect( m_mediaPlayer,
SIGNAL( endReached() ),
this,
SLOT( endReached() ) );
//TODO: add EndReached event.
......@@ -134,3 +142,9 @@ void PreviewWidget::videoPlaying()
{
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/pause" ) );
}
void PreviewWidget::endReached()
{
m_mediaPlayer->stop();
m_ui->seekSlider->setValue( 0 );
}
......@@ -27,6 +27,7 @@
#include <QDragEnterEvent>
#include "VLCMediaPlayer.h"
#include "VLCMediaList.h"
namespace Ui {
class PreviewWidget;
......@@ -51,10 +52,12 @@ private slots:
void seekSliderMoved( int value );
void videoPaused();
void videoPlaying();
void endReached();
private:
Ui::PreviewWidget* m_ui;
LibVLCpp::MediaPlayer* m_mediaPlayer;
// LibVLCpp::MediaList* m_mediaList;
bool m_clipLoaded;
};
......
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