1
/*  This file is part of the KDE project
2
    Copyright (C) 2004-2007 Matthias Kretz <kretz@kde.org>
3
4
    This library is free software; you can redistribute it and/or
5
    modify it under the terms of the GNU Lesser General Public
6
    License as published by the Free Software Foundation; either
7
    version 2.1 of the License, or (at your option) version 3, or any
8
    later version accepted by the membership of KDE e.V. (or its
9
    successor approved by the membership of KDE e.V.), Nokia Corporation 
10
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
11
    act as a proxy defined in Section 6 of version 3 of the license.
12
13
    This library is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
    Lesser General Public License for more details.
17
18
    You should have received a copy of the GNU Lesser General Public 
19
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
21
*/
22
23
#include "videoplayer.h"
24
#include "mediaobject.h"
25
#include "audiooutput.h"
26
#include "videowidget.h"
27
#include "path.h"
28
#include <QtGui/QBoxLayout>
29
30
QT_BEGIN_NAMESPACE
31
32
#ifndef QT_NO_PHONON_VIDEOPLAYER
33
34
namespace Phonon
35
{
36
37
class VideoPlayerPrivate
38
{
39
    public:
40
        VideoPlayerPrivate()
41
            : player(0)
42
            , aoutput(0)
43
            , voutput(0) {}
44
45
        void init(VideoPlayer *q, Phonon::Category category);
46
47
        MediaObject *player;
48
        AudioOutput *aoutput;
49
        VideoWidget *voutput;
50
51
        MediaSource src;
52
};
53
54
void VideoPlayerPrivate::init(VideoPlayer *q, Phonon::Category category)
55
{
56
    QVBoxLayout *layout = new QVBoxLayout(q);
57
    layout->setMargin(0);
58
59
    aoutput = new AudioOutput(category, q);
60
61
    voutput = new VideoWidget(q);
62
    layout->addWidget(voutput);
63
64
    player = new MediaObject(q);
65
    Phonon::createPath(player, aoutput);
66
    Phonon::createPath(player, voutput);
67
68
    q->connect(player, SIGNAL(finished()), SIGNAL(finished()));
69
}
70
71
VideoPlayer::VideoPlayer(Phonon::Category category, QWidget *parent)
72
    : QWidget(parent)
73
    , d(new VideoPlayerPrivate)
74
{
75
    d->init(this, category);
76
}
77
78
VideoPlayer::VideoPlayer(QWidget *parent)
79
    : QWidget(parent)
80
    , d(new VideoPlayerPrivate)
81
{
82
    d->init(this, Phonon::VideoCategory);
83
}
84
85
VideoPlayer::~VideoPlayer()
86
{
87
    delete d;
88
}
89
90
MediaObject *VideoPlayer::mediaObject() const
91
{
92
    return d->player;
93
}
94
95
AudioOutput *VideoPlayer::audioOutput() const
96
{
97
    return d->aoutput;
98
}
99
100
VideoWidget *VideoPlayer::videoWidget() const
101
{
102
    return d->voutput;
103
}
104
105
void VideoPlayer::load(const MediaSource &source)
106
{
107
    d->player->setCurrentSource(source);
108
}
109
110
void VideoPlayer::play(const MediaSource &source)
111
{
112
    if (source == d->player->currentSource()) {
113
        if (!isPlaying())
114
            d->player->play();
115
        return;
116
    }
117
    // new URL
118
    d->player->setCurrentSource(source);
119
        
120
    if (ErrorState == d->player->state())
121
        return;
122
123
    d->player->play();
124
}
125
126
void VideoPlayer::play()
127
{
128
    d->player->play();
129
}
130
131
void VideoPlayer::pause()
132
{
133
    d->player->pause();
134
}
135
136
void VideoPlayer::stop()
137
{
138
    d->player->stop();
139
}
140
141
qint64 VideoPlayer::totalTime() const
142
{
143
    return d->player->totalTime();
144
}
145
146
qint64 VideoPlayer::currentTime() const
147
{
148
    return d->player->currentTime();
149
}
150
151
void VideoPlayer::seek(qint64 ms)
152
{
153
    d->player->seek(ms);
154
}
155
156
float VideoPlayer::volume() const
157
{
158
    return d->aoutput->volume();
159
}
160
161
void VideoPlayer::setVolume(float v)
162
{
163
    d->aoutput->setVolume(v);
164
}
165
166
bool VideoPlayer::isPlaying() const
167
{
168
    return (d->player->state() == PlayingState);
169
}
170
171
bool VideoPlayer::isPaused() const
172
{
173
    return (d->player->state() == PausedState);
174
}
175
176
} // namespaces
177
178
#endif //QT_NO_PHONON_VIDEOPLAYER
179
180
QT_END_NAMESPACE
181
182
#include "moc_videoplayer.cpp"
183
184
// vim: sw=4 ts=4