Phonon

videoplayer.cpp
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 <QBoxLayout>
29#include <QEvent>
30
31#ifndef QT_NO_PHONON_VIDEOPLAYER
32
33namespace Phonon
34{
35
36class VideoPlayerPrivate
37{
38 public:
39 VideoPlayerPrivate()
40 : player(nullptr)
41 , aoutput(nullptr)
42 , voutput(nullptr)
43 , category(Phonon::NoCategory)
44 , initialized(false) {}
45
46 void ensureCreated() const;
47
48 mutable MediaObject *player;
49 mutable AudioOutput *aoutput;
50 mutable VideoWidget *voutput;
51
52 mutable MediaSource src;
53 mutable Phonon::Category category;
54 mutable bool initialized;
55 VideoPlayer *q_ptr;
56};
57
58void VideoPlayerPrivate::ensureCreated() const
59{
60 if (!initialized) {
61 initialized = true;
62 QVBoxLayout *layout = new QVBoxLayout(q_ptr);
64
65 aoutput = new AudioOutput(category, q_ptr);
66 voutput = new VideoWidget(q_ptr);
67 layout->addWidget(voutput);
68
69 player = new MediaObject(q_ptr);
70 Phonon::createPath(player, aoutput);
71 Phonon::createPath(player, voutput);
72
73 q_ptr->connect(player, SIGNAL(finished()), SIGNAL(finished()));
74 }
75}
76
77VideoPlayer::VideoPlayer(Phonon::Category category, QWidget *parent)
78 : QWidget(parent)
79 , d(new VideoPlayerPrivate)
80{
81 d->q_ptr = this;
82 d->category = category;
83}
84
86 : QWidget(parent)
87 , d(new VideoPlayerPrivate)
88{
89 d->q_ptr = this;
90 d->category = Phonon::VideoCategory;
91}
92
94{
95 delete d;
96}
97
99{
100 d->ensureCreated();
101 return d->player;
102}
103
105{
106 d->ensureCreated();
107 return d->aoutput;
108}
109
111{
112 d->ensureCreated();
113 return d->voutput;
114}
115
117{
118 d->ensureCreated();
119 d->player->setCurrentSource(source);
120}
121
123{
124 d->ensureCreated();
125 if (source == d->player->currentSource()) {
126 if (!isPlaying())
127 d->player->play();
128 return;
129 }
130 // new URL
131 d->player->setCurrentSource(source);
132
133 if (ErrorState == d->player->state())
134 return;
135
136 d->player->play();
137}
138
140{
141 d->ensureCreated();
142 d->player->play();
143}
144
146{
147 d->ensureCreated();
148 d->player->pause();
149}
150
152{
153 d->ensureCreated();
154 d->player->stop();
155}
156
158{
159 d->ensureCreated();
160 return d->player->totalTime();
161}
162
164{
165 d->ensureCreated();
166 return d->player->currentTime();
167}
168
169void VideoPlayer::seek(qint64 ms)
170{
171 d->ensureCreated();
172 d->player->seek(ms);
173}
174
176{
177 d->ensureCreated();
178 return d->aoutput->volume();
179}
180
182{
183 d->ensureCreated();
184 d->aoutput->setVolume(v);
185}
186
188{
189 d->ensureCreated();
190 return (d->player->state() == PlayingState);
191}
192
194{
195 d->ensureCreated();
196 return (d->player->state() == PausedState);
197}
198
199bool VideoPlayer::event(QEvent *e) {
200 if (e->type() == QEvent::Show)
201 d->ensureCreated();
202 return QWidget::event(e);
203}
204
205} // namespaces
206
207#endif //QT_NO_PHONON_VIDEOPLAYER
208
209#include "moc_videoplayer.cpp"
210
211// vim: sw=4 ts=4
Class for audio output to the soundcard.
Definition audiooutput.h:49
qreal volume
This is the current loudness of the output (it is using Stevens' law to calculate the change in volta...
Definition audiooutput.h:67
Interface for media playback of a given URL.
void setCurrentSource(const MediaSource &source)
Set the media source the MediaObject should use.
void stop()
Requests playback to stop.
State state() const
Get the current state.
void pause()
Requests playback to pause.
qint64 currentTime() const
Get the current time (in milliseconds) of the file currently being played.
void play()
Requests playback of the media data to start.
void seek(qint64 time)
Requests a seek to the time indicated.
qint64 totalTime() const
Get the total time (in milliseconds) of the file currently being played.
MediaSource currentSource() const
Returns the current media source.
Note that all constructors of this class are implicit, so that you can simply write.
void seek(qint64 ms)
Seeks to the requested time.
float volume() const
This is the current volume of the output as voltage factor.
qint64 totalTime() const
Get the total time (in milliseconds) of the file currently being played.
VideoWidget * videoWidget() const
getter for the VideoWidget.
VideoPlayer(Phonon::Category category, QWidget *parent=nullptr)
Constructs a new VideoPlayer instance.
bool isPaused() const
void load(const Phonon::MediaSource &source)
Starts preloading the media data and fill audiobuffers in the backend.
qint64 currentTime() const
Get the current time (in milliseconds) of the file currently being played.
void setVolume(float volume)
Sets the volume of the output as voltage factor.
void play()
Continues playback of a paused media.
void pause()
Pauses the playback.
~VideoPlayer() override
On destruction the playback is stopped, also the audio output is removed so that the desktop mixer wi...
MediaObject * mediaObject() const
getter for the MediaObject.
AudioOutput * audioOutput() const
getter for the AudioOutput.
bool isPlaying() const
void stop()
Stops the playback.
Widget to display video.
Definition videowidget.h:55
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
Type type() const const
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:16 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.