Commit 8f737bf9 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Use of get/setPosition instead of get/setTime in the preview

xPosition is more efficient and make the code less error-prone than
time-based.
parent 72798bda
......@@ -41,6 +41,7 @@ MediaPlayer::MediaPlayer( Media* media, bool playStop /* = true*/ )
libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerStopped, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
}
/**
......@@ -75,7 +76,9 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
case libvlc_MediaPlayerTimeChanged:
self->timeChangedFilter();
break;
// case libvlc_MediaPlayerPositionChanged:
case libvlc_MediaPlayerPositionChanged:
self->emit positionChanged();
break;
// case libvlc_MediaPlayerSeekableChanged:
// case libvlc_MediaPlayerPausableChanged:
// case libvlc_MediaListItemAdded:
......@@ -131,6 +134,19 @@ void MediaPlayer::setTime( qint64 time )
m_ex.checkThrow();
}
float MediaPlayer::getPosition()
{
float p = libvlc_media_player_get_position( m_internalPtr, m_ex );
m_ex.checkThrow();
return p;
}
void MediaPlayer::setPosition( float pos )
{
libvlc_media_player_set_position( m_internalPtr, pos, m_ex );
m_ex.checkThrow();
}
qint64 MediaPlayer::getLength()
{
qint64 length = libvlc_media_player_get_length( m_internalPtr, m_ex );
......
......@@ -44,6 +44,8 @@ namespace LibVLCpp
void stop();
qint64 getTime();
void setTime( qint64 time );
float getPosition();
void setPosition( float pos );
qint64 getLength();
void takeSnapshot( char* outputFile, unsigned int width, unsigned int heigth );
bool isPlaying();
......@@ -65,6 +67,7 @@ namespace LibVLCpp
void paused();
void stopped();
void endReached();
void positionChanged();
};
}
......
......@@ -134,3 +134,13 @@ bool Media::isPlaying()
{
return m_vlcMediaPlayer->isPlaying();
}
float Media::getPosition()
{
return m_vlcMediaPlayer->getPosition();
}
void Media::setPosition( float pos )
{
m_vlcMediaPlayer->setPosition( pos );
}
......@@ -63,6 +63,14 @@ public:
* Ask libvlc if the media is currently playing
*/
virtual bool isPlaying();
/**
* Return the current position in the media as a float.
*/
float getPosition();
/**
* Set the current position in the media as a float.
*/
void setPosition( float pos );
protected:
//Protected constructor so we can't use a Media without its sub-implementation
......
......@@ -30,6 +30,10 @@ PreviewWidget::PreviewWidget( QWidget *parent ) :
{
m_ui->setupUi( this );
m_ui->groupBoxButton->hide();
m_ui->seekSlider->setMinimum( 0 );
m_ui->seekSlider->setMaximum( 1000 );
m_ui->seekSlider->setSingleStep( 2 );
m_ui->seekSlider->setFocusPolicy( Qt::NoFocus );
char const *vlc_argv[] =
{
......@@ -99,17 +103,16 @@ void PreviewWidget::dropEvent( QDropEvent* event )
SLOT ( videoPlaying() ) );
m_currentMedia->play();
connect( m_currentMedia->mediaPlayer(),
SIGNAL( timeChanged() ),
SIGNAL( positionChanged() ),
this,
SLOT( videoTimeChanged() ) );
SLOT( positionChanged() ) );
}
void PreviewWidget::videoTimeChanged()
void PreviewWidget::positionChanged()
{
if ( m_currentMedia )
{
m_ui->seekSlider->setMaximum( m_currentMedia->getLength() / 100 );
m_ui->seekSlider->setSliderPosition( m_currentMedia->getTime() / 100 );
m_ui->seekSlider->setValue( (float)m_currentMedia->getPosition() * 1000 );
}
}
......@@ -117,7 +120,7 @@ void PreviewWidget::seekSliderMoved( int )
{
if ( m_currentMedia )
{
m_currentMedia->setTime( m_ui->seekSlider->value() * 100 );
m_currentMedia->setPosition( (float)m_ui->seekSlider->value() / 1000 );
}
}
......@@ -126,13 +129,9 @@ void PreviewWidget::on_pushButtonPlay_clicked()
if ( m_currentMedia == NULL )
return;
if ( m_currentMedia->isPlaying() )
{
m_currentMedia->pause();
}
else
{
m_currentMedia->play();
}
}
void PreviewWidget::videoPaused()
......
......@@ -47,7 +47,7 @@ protected:
private slots:
void on_pushButtonPlay_clicked();
void videoTimeChanged();
void positionChanged();
void seekSliderMoved( int value );
void videoPaused();
void videoPlaying();
......
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