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
#ifndef Phonon_VIDEOPLAYER_H
24
#define Phonon_VIDEOPLAYER_H
25
26
#include "phonon_export.h"
27
#include "phononnamespace.h"
28
#include "mediasource.h"
29
#include <QtGui/QWidget>
30
31
QT_BEGIN_HEADER
32
QT_BEGIN_NAMESPACE
33
34
#ifndef QT_NO_PHONON_VIDEOPLAYER
35
36
namespace Phonon
37
{
38
class VideoPlayerPrivate;
39
class MediaObject;
40
class AudioOutput;
41
class VideoWidget;
42
43
/** \class VideoPlayer videoplayer.h Phonon/VideoPlayer
44
 * \short Playback class for simple tasks.
45
 *
46
 * With %VideoPlayer you can get results quickly and easily. You can do the standard
47
 * playback tasks like play, pause and stop, but also set a playback volume and
48
 * seek (there's no guarantee that the seek will work, though).
49
 *
50
 * Keep in mind that when the %VideoPlayer instance is deleted the playback will
51
 * stop.
52
 *
53
 * A play and forget code example:
54
 * \code
55
 * VideoPlayer *player = new VideoPlayer(parentWidget);
56
 * connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
57
 * player->play(url);
58
 * \endcode
59
 *
60
 * \ingroup Playback
61
 * \ingroup PhononVideo
62
 * \author Matthias Kretz <kretz@kde.org>
63
 */
64
class PHONON_EXPORT VideoPlayer : public QWidget
65
{
66
    Q_OBJECT
67
    public:
68
        /**
69
         * Constructs a new %VideoPlayer instance.
70
         *
71
         * \param category The category used for the audio output device.
72
         * \param parent The QObject parent.
73
         */
74
        explicit VideoPlayer(Phonon::Category category, QWidget *parent = 0);
75
76
        /**
77
         * Constructs a new video widget with a \p parent
78
         * using Phonon::VideoCategory as its category.
79
         *
80
         * \param parent The QObject parent.
81
         */
82
        VideoPlayer(QWidget *parent = 0);
83
84
        /**
85
         * On destruction the playback is stopped, also the audio output is
86
         * removed so that the desktop mixer will not show the application
87
         * anymore. If you need a persistent audio output don't use
88
         * %VideoPlayer but MediaObject, VideoPath and VideoOutput.
89
         */
90
        ~VideoPlayer();
91
92
        /**
93
         * Get the total time (in milliseconds) of the file currently being played.
94
         */
95
        qint64 totalTime() const;
96
        /**
97
         * Get the current time (in milliseconds) of the file currently being played.
98
         */
99
        qint64 currentTime() const;
100
        /**
101
         * This is the current volume of the output as voltage factor.
102
         *
103
         * 1.0 means 100%, 0.5 means 50% voltage/25% power, 0.0 means 0%
104
         */
105
        float volume() const;
106
107
        /**
108
         * \returns \c true if it is currently playing
109
         * \returns \c false if it is currently stopped or paused
110
         */
111
        bool isPlaying() const;
112
        /**
113
         * \returns \c true if it is currently paused
114
         * \returns \c false if it is currently playing or stopped
115
         */
116
        bool isPaused() const;
117
118
        /**
119
         * getter for the MediaObject.
120
         */
121
        MediaObject *mediaObject() const;
122
123
        /**
124
         * getter for the AudioOutput.
125
         */
126
        AudioOutput *audioOutput() const;
127
128
        /**
129
         * getter for the VideoWidget.
130
         */
131
        VideoWidget *videoWidget() const;
132
133
    public Q_SLOTS:
134
        /**
135
         * Starts preloading the media data and fill audiobuffers in the
136
         * backend.
137
         *
138
         * When there's already a media playing (or paused) it will be stopped
139
         * (the finished signal will not be emitted).
140
         */
141
        void load(const Phonon::MediaSource &source);
142
143
        /**
144
         * Play the media at the given URL. Starts playback as fast as possible.
145
         * This can take a considerable time depending on the URL and the
146
         * backend.
147
         *
148
         * If you need low latency between calling play() and the sound actually
149
         * starting to play on your output device you need to use MediaObject
150
         * and be able to set the URL before calling play(). Note that
151
         * \code
152
         * audioPlayer->load(url);
153
         * audioPlayer->play();
154
         * \endcode
155
         * doesn't make a difference: the application should be idle between the
156
         * load and play calls so that the backend can start preloading the
157
         * media and fill audio buffers.
158
         */
159
        void play(const Phonon::MediaSource &source);
160
161
        /**
162
         * Continues playback of a paused media. Restarts playback of a stopped
163
         * media.
164
         */
165
        void play();
166
        /**
167
         * Pauses the playback.
168
         */
169
        void pause();
170
        /**
171
         * Stops the playback.
172
         */
173
        void stop();
174
175
        /**
176
         * Seeks to the requested time. Note that the backend is free to ignore
177
         * the seek request if the media source isn't seekable.
178
         *
179
         * \param ms Time in milliseconds from the start of the media.
180
         */
181
        void seek(qint64 ms);
182
        /**
183
         * Sets the volume of the output as voltage factor.
184
         *
185
         * 1.0 means 100%, 0.5 means 50% voltage/25% power, 0.0 means 0%
186
         */
187
        void setVolume(float volume);
188
189
    Q_SIGNALS:
190
        /**
191
         * This signal is emitted when the playback finished.
192
         */
193
        void finished();
194
195
    protected:
196
        VideoPlayerPrivate *const d;
197
};
198
199
} //namespace Phonon
200
201
#endif //QT_NO_PHONON_VIDEOPLAYER
202
203
QT_END_NAMESPACE
204
QT_END_HEADER
205
206
#endif // Phonon_VIDEOPLAYER_H
207
// vim: sw=4 ts=4 tw=80