videoplayer.cpp 3.22 KB
Newer Older
1
/*  This file is part of the KDE project
2
    Copyright (C) 2004-2007 Matthias Kretz <kretz@kde.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include "videoplayer.h"
21
22
#include "mediaobject.h"
#include "audiooutput.h"
23
#include "videowidget.h"
24
#include "path.h"
Dirk Mueller's avatar
Dirk Mueller committed
25
#include <QtGui/QBoxLayout>
26

Thierry Bastian's avatar
Thierry Bastian committed
27
28
QT_BEGIN_NAMESPACE

29
30
31
namespace Phonon
{

32
class VideoPlayerPrivate
33
{
34
    public:
35
        VideoPlayerPrivate()
36
37
38
            : player(0)
        {
        }
39

40
41
42
        MediaObject *player;
        AudioOutput *aoutput;
        VideoWidget *voutput;
43

44
        MediaSource src;
45
46
};

47
48
VideoPlayer::VideoPlayer(Phonon::Category category, QWidget *parent)
    : QWidget(parent)
49
    , d(new VideoPlayerPrivate)
50
{
51
    QVBoxLayout *layout = new QVBoxLayout(this);
52
    layout->setMargin(0);
53

54
    d->aoutput = new AudioOutput(category, this);
55

56
57
    d->voutput = new VideoWidget(this);
    layout->addWidget(d->voutput);
58

59

60
    d->player = new MediaObject(this);
61
62
    Phonon::createPath(d->player, d->aoutput);
    Phonon::createPath(d->player, d->voutput);
63

64
    connect(d->player, SIGNAL(finished()), SIGNAL(finished()));
65
66
67
68
}

VideoPlayer::~VideoPlayer()
{
Pino Toscano's avatar
Pino Toscano committed
69
    delete d;
70
71
}

72
MediaObject *VideoPlayer::mediaObject() const
73
{
74
    return d->player;
75
76
}

77
AudioOutput *VideoPlayer::audioOutput() const
78
{
79
80
81
82
83
84
    return d->aoutput;
}

VideoWidget *VideoPlayer::videoWidget() const
{
    return d->voutput;
85
86
}

87
void VideoPlayer::load(const MediaSource &source)
88
{
89
    d->player->setCurrentSource(source);
90
91
}

92
void VideoPlayer::play(const MediaSource &source)
93
{
94
    if (source == d->player->currentSource()) {
95
96
97
98
99
        if (!isPlaying())
            d->player->play();
        return;
    }
    // new URL
100
    d->player->setCurrentSource(source);
101
102
103
        
    if (ErrorState == d->player->state())
        return;
104

105
106
    if (StoppedState == d->player->state())
        d->player->play();
107
108
109
110
}

void VideoPlayer::play()
{
111
    d->player->play();
112
113
114
115
}

void VideoPlayer::pause()
{
116
    d->player->pause();
117
118
119
120
}

void VideoPlayer::stop()
{
121
    d->player->stop();
122
123
124
125
}

qint64 VideoPlayer::totalTime() const
{
126
    return d->player->totalTime();
127
128
129
130
}

qint64 VideoPlayer::currentTime() const
{
131
    return d->player->currentTime();
132
133
}

134
void VideoPlayer::seek(qint64 ms)
135
{
136
    d->player->seek(ms);
137
138
139
140
}

float VideoPlayer::volume() const
{
141
    return d->aoutput->volume();
142
143
}

144
void VideoPlayer::setVolume(float v)
145
{
146
    d->aoutput->setVolume(v);
147
148
149
150
}

bool VideoPlayer::isPlaying() const
{
151
    return (d->player->state() == PlayingState);
152
153
154
155
}

bool VideoPlayer::isPaused() const
{
156
    return (d->player->state() == PausedState);
157
158
159
160
}

} // namespaces

Thierry Bastian's avatar
Thierry Bastian committed
161
162
QT_END_NAMESPACE

Matthias Kretz's avatar
Matthias Kretz committed
163
#include "moc_videoplayer.cpp"
164

165
// vim: sw=4 ts=4