Media.cpp 3.29 KB
Newer Older
Christophe Courtaut's avatar
Christophe Courtaut committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*****************************************************************************
 * Media.cpp: Generic class for media handling
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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
#include <QtDebug>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
24
25
#include "Media.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
26
27
Media::Media(LibVLCpp::Instance* instance, const QString& mrl )
    : m_instance( NULL ), m_vlcMedia( NULL ), m_vlcMediaPlayer( NULL ),
28
    m_mrl( mrl ), m_instanceOwned( false )
29
{
30
    if ( !instance )
31
    {
32
        char const *vlc_argv[] =
33
        {
Ludovic Fauvet's avatar
Ludovic Fauvet committed
34
            //"-vvvvv",
35
            "--no-skip-frames",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
36
            "--no-audio",
37
38
39
40
41
            //"--plugin-path", VLC_TREE "/modules",
            //"--ignore-config", //Don't use VLC's config files
        };
        int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv );
        instance = new LibVLCpp::Instance( vlc_argc, vlc_argv );
42
        m_instanceOwned = true;
43
    }
44
    m_instance = instance;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
45

46
    m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
47
48
}

49
Media::~Media()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
50
{
51
52
    if ( m_instance  && m_instanceOwned == true )
    {
53
        delete m_instance;
54
    }
55
    if ( m_vlcMedia )
56
    {
57
        delete m_vlcMedia;
58
    }
59
    if ( m_vlcMediaPlayer )
60
    {
61
        delete m_vlcMediaPlayer;
62
    }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
63
64
}

65
void        Media::loadMedia( const QString& mrl )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
66
{
67
68
69
    if ( m_vlcMedia )
        delete m_vlcMedia;
    m_mrl = mrl;
70

71
    m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
72
}
73

74
void        Media::setupMedia()
75
{
76
77
    if ( m_vlcMediaPlayer )
        delete m_vlcMediaPlayer;
78

79
80
81
82
    //Flushing the args into the media :
    QString     param;
    foreach ( param, m_parameters )
        m_vlcMedia->addOption( param.toStdString().c_str() );
83

84
    m_vlcMediaPlayer = new LibVLCpp::MediaPlayer( m_vlcMedia );
85
}
86
87

void        Media::play()
88
{
89
    if ( !m_vlcMediaPlayer )
90
        setupMedia();
91
92
93
    m_vlcMediaPlayer->play();
}

94
95
96
97
98
99
100
101
102
103
104
105
106
107
void        Media::pause()
{
    if ( m_vlcMediaPlayer == NULL )
        return;
    m_vlcMediaPlayer->pause();
}

void        Media::stop()
{
    if ( m_vlcMediaPlayer == NULL )
        return;
    m_vlcMediaPlayer->stop();
}

108
void        Media::addParam( const QString& param )
109
{
110
    m_parameters.append( param );
111
}
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

void        Media::setDrawable( WId handle )
{
    m_vlcMediaPlayer->setDrawable( handle );
}

qint64      Media::getLength()
{
    return m_vlcMediaPlayer->getLength();
}

qint64      Media::getTime()
{
    return m_vlcMediaPlayer->getTime();
}

void        Media::setTime( qint64 time )
{
    m_vlcMediaPlayer->setTime( time );
}