ClipPreviewWidget.cpp 3.2 KB
Newer Older
Christophe Courtaut's avatar
Christophe Courtaut committed
1
/*****************************************************************************
2
 * ClipPreviewWidget: Preview widget
Christophe Courtaut's avatar
Christophe Courtaut committed
3 4 5
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
6
 * Authors: Geoffroy Lacarrière <geoffroylaca@gmail.com>
Christophe Courtaut's avatar
Christophe Courtaut committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24
#include <QtDebug>

25
#include "ClipPreviewWidget.h"
geoff's avatar
geoff committed
26

27
ClipPreviewWidget::ClipPreviewWidget( QWidget* renderWidget ) :
28
    GenericPreviewWidget( renderWidget ),
29
    m_clipLoaded( false ), m_videoStopped( true ), m_vlcMedia( NULL )
geoff's avatar
geoff committed
30 31 32
{
}

33
ClipPreviewWidget::~ClipPreviewWidget()
geoff's avatar
geoff committed
34 35
{
}
36

37
void        ClipPreviewWidget::startPreview( Media* media )
38
{
39 40 41 42 43
    if ( m_vlcMedia != NULL )
        delete m_vlcMedia;
    m_vlcMedia = new LibVLCpp::Media( media->getVLCMedia() );

    m_mediaPlayer->setMedia( m_vlcMedia );
44

45 46 47 48 49
    connect( m_mediaPlayer,     SIGNAL( stopped() ),            this,   SLOT( __videoPaused() ) );
    connect( m_mediaPlayer,     SIGNAL( paused() ),             this,   SLOT( __videoPaused() ) );
    connect( m_mediaPlayer,     SIGNAL( playing() ),            this,   SLOT( __videoPlaying() ) );
    connect( m_mediaPlayer,     SIGNAL( positionChanged() ),    this,   SLOT( __positionChanged() ) );
    connect( m_mediaPlayer,     SIGNAL( endReached() ),         this,   SLOT( __endReached() ) );
50 51

    m_mediaPlayer->play();
52
    m_clipLoaded = true;
53
    m_videoStopped = false;
54 55
}

56
void        ClipPreviewWidget::setPosition( float newPos )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
57
{
58
    if ( m_clipLoaded == false || m_videoStopped == true )
59
        return ;
60
    m_mediaPlayer->setPosition( newPos );
61 62
}

63
void        ClipPreviewWidget::togglePlayPause( bool forcePause )
64
{
65 66
    if ( m_clipLoaded == false)
        return ;
67 68 69
    if ( m_videoStopped == true )
        m_videoStopped = false;

70 71
    if ( m_mediaPlayer->isPlaying() )
        m_mediaPlayer->pause();
72
    else if ( forcePause == false )
73
        m_mediaPlayer->play();
74
}
75

76 77 78 79 80 81 82 83 84
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
void        ClipPreviewWidget::__videoPaused()
{
    emit paused();
}

void        ClipPreviewWidget::__videoPlaying()
85
{
86
    emit playing();
87 88
}

89
void        ClipPreviewWidget::__positionChanged()
90
{
91 92 93
    if ( m_clipLoaded == false)
        return ;
    emit positionChanged( m_mediaPlayer->getPosition() );
94
}
95

96
void        ClipPreviewWidget::__endReached()
97 98
{
    m_mediaPlayer->stop();
99
    m_videoStopped = true;
100
    emit endReached();
101
}