File: mediaelement.h

package info (click to toggle)
phonon 4%3A4.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,288 kB
  • sloc: cpp: 16,079; sh: 62; makefile: 58; xml: 32; awk: 22
file content (196 lines) | stat: -rw-r--r-- 6,019 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
    Copyright (C) 2011 Harald Sitter <sitter@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), Nokia Corporation
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ABSTRACTMEDIAELEMENT_H
#define ABSTRACTMEDIAELEMENT_H

#include <QtCore/QUrl>
#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeParserStatus>

#include <phonon/phononnamespace.h>

#include "abstractinitable.h"

namespace Phonon {
namespace Declarative {

class MetaData;

/**
 * This is the Qt Quick Element encasing a Phonon::VideoGraphicsObject.
 * For general information regarding capabilities please see the documentation
 * of Phonon::VideoGraphicsObject.
 *
 * Like every Phonon Qt Quick class this class provides semi-lazy initialization
 * as provided described by the AbstractInitAble class.
 *
 * This element cannot be decorated by another output. If you still try to do
 * so the output will simply attach to the MediaObject this VideoOutputElement
 * was attached to.
 *
 * \see Phonon::VideoGraphicsObject
 * \author Harald Sitter <sitter@kde.org>
 */
class MediaElement : public QDeclarativeItem, AbstractInitAble
{
    Q_OBJECT
    Q_INTERFACES(QDeclarativeParserStatus)
    Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)

    Q_PROPERTY(bool playing READ isPlaying NOTIFY playingChanged)
    Q_PROPERTY(bool paused READ isPaused NOTIFY pausedChanged)
    Q_PROPERTY(bool stopped READ isStopped NOTIFY stoppedChanged)

    Q_PROPERTY(bool video READ hasVideo NOTIFY hasVideoChanged)
    Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
    Q_PROPERTY(qint32 tickInterval READ tickInterval WRITE setTickInterval)
    Q_PROPERTY(qreal totalTime READ totalTime NOTIFY totalTimeChanged)
    Q_PROPERTY(qreal time READ time WRITE seek NOTIFY timeChanged)

    Q_PROPERTY(Phonon::Declarative::MetaData *metaData READ metaData CONSTANT)
public:
    MediaElement(QDeclarativeItem *parent = 0);
    virtual ~MediaElement();

    /// \reimp
    void classBegin();

    /// \reimp
    void componentComplete();

    /// \reimp
    virtual void init(MediaObject *mediaObject = 0);

    MediaObject *mediaObject() const { return m_mediaObject; }

    /// \see Phonon::MediaObject::currentSource
    QUrl source() const;

    /// \see Phonon::MediaObject::setCurrentSource
    void setSource(const QUrl &url);

    /// \returns \c true when current state is playing, \c false otherwise
    bool isPlaying() const;

    /// \returns \c true when current state is paused, \c false otherwise
    bool isPaused() const;

    /// \returns \c true when current state is stopped, \c false otherwise
    bool isStopped() const;

    /// \see Phonon::MediaObject::hasVideo
    bool hasVideo() const;

    /// \see Phonon::MediaObject::isSeekable
    bool isSeekable() const;

    /// \see Phonon::MediaObject::tickInterval
    qint32 tickInterval() const;

    /// \see Phonon::MediaObject::setTickInterval
    void setTickInterval(qint32 interval);

    /// \see Phonon::MediaObject::totalTime
    qreal totalTime() const;

    /// \see Phonon::MediaObject::currentTime
    qreal time() const;

    /// \see Phonon::MediaObject::seek
    void seek(qreal time);

    /**
     * The MetaData held within the element. The MetaData is static and thus this
     * call is relatively cheap.
     * The MetaData stays valid for as long as the MediaElement exists.
     *
     * \returns the MetaData container of this MediaElement
     */
    MetaData *metaData();

signals:
    /// emitted when the (current) source changed
    void sourceChanged();

    /// emitted when the state changed
    void stateChanged();

    /// emitted when the playing property changed
    void playingChanged();

    /// emitted when the paused property changed
    void pausedChanged();

    /// emitted when the stopped property changed
    void stoppedChanged();

    /// emitted when a video was detected
    void hasVideoChanged();

    /// emitted when the seekability changed
    void seekableChanged();

    /// emitted when the total time (length) changed
    void totalTimeChanged();

    /// emitted when the current playback time (elapsed time) changed
    void timeChanged();

public slots:
    /// Starts playing.
    void play();

    /// Pauses media (if it was playing -> no effect otherwise).
    void pause();

    /// Stops playing.
    void stop();

private slots:
    /// Called when MediaObject is aboutToFinish
    void handleFinished();

    /// Translates a state change to explicit singnals on the properties that changed
    void handleStateChange(Phonon::State newState, Phonon::State oldState);

protected:
    /// The current state of the media.
    State m_state;

    /// Whether or not the media has finished playing.
    bool m_finished;

private:
    /// Translates a state change to an explicit signal for playing, paused etc.
    void emitStateChanges(Phonon::State state);

    /// The current source
    QUrl m_source;

    /// The MetaData container of this element (lazy-init, so null by default)
    MetaData *m_metaData;
};

} // namespace Declarative
} // namespace Phonon

#endif // ABSTRACTMEDIAELEMENT_H