1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QMEDIAPLAYER_H
41#define QMEDIAPLAYER_H
42
43#include <QtMultimedia/qtmultimediaglobal.h>
44#include <QtMultimedia/qmediaobject.h>
45#include <QtMultimedia/qmediacontent.h>
46#include <QtMultimedia/qmediaenumdebug.h>
47#include <QtMultimedia/qaudio.h>
48
49#include <QtNetwork/qnetworkconfiguration.h>
50
51QT_BEGIN_NAMESPACE
52
53
54class QAbstractVideoSurface;
55class QMediaPlaylist;
56class QVideoWidget;
57class QGraphicsVideoItem;
58
59class QMediaPlayerPrivate;
60class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaObject
61{
62 Q_OBJECT
63 Q_PROPERTY(QMediaContent media READ media WRITE setMedia NOTIFY mediaChanged)
64 Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged)
65 Q_PROPERTY(QMediaPlaylist* playlist READ playlist WRITE setPlaylist)
66 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
67 Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged)
68 Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged)
69 Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
70 Q_PROPERTY(int bufferStatus READ bufferStatus NOTIFY bufferStatusChanged)
71 Q_PROPERTY(bool audioAvailable READ isAudioAvailable NOTIFY audioAvailableChanged)
72 Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged)
73 Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
74 Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
75 Q_PROPERTY(State state READ state NOTIFY stateChanged)
76 Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
77 Q_PROPERTY(QAudio::Role audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged)
78 Q_PROPERTY(QString customAudioRole READ customAudioRole WRITE setCustomAudioRole NOTIFY customAudioRoleChanged)
79 Q_PROPERTY(QString error READ errorString)
80 Q_ENUMS(State)
81 Q_ENUMS(MediaStatus)
82 Q_ENUMS(Error)
83
84public:
85 enum State
86 {
87 StoppedState,
88 PlayingState,
89 PausedState
90 };
91
92 enum MediaStatus
93 {
94 UnknownMediaStatus,
95 NoMedia,
96 LoadingMedia,
97 LoadedMedia,
98 StalledMedia,
99 BufferingMedia,
100 BufferedMedia,
101 EndOfMedia,
102 InvalidMedia
103 };
104
105 enum Flag
106 {
107 LowLatency = 0x01,
108 StreamPlayback = 0x02,
109 VideoSurface = 0x04
110 };
111 Q_DECLARE_FLAGS(Flags, Flag)
112
113 enum Error
114 {
115 NoError,
116 ResourceError,
117 FormatError,
118 NetworkError,
119 AccessDeniedError,
120 ServiceMissingError,
121 MediaIsPlaylist
122 };
123
124 explicit QMediaPlayer(QObject *parent = nullptr, Flags flags = Flags());
125 ~QMediaPlayer();
126
127 static QMultimedia::SupportEstimate hasSupport(const QString &mimeType,
128 const QStringList& codecs = QStringList(),
129 Flags flags = Flags());
130 static QStringList supportedMimeTypes(Flags flags = Flags());
131
132 void setVideoOutput(QVideoWidget *);
133 void setVideoOutput(QGraphicsVideoItem *);
134 void setVideoOutput(QAbstractVideoSurface *surface);
135 void setVideoOutput(const QVector<QAbstractVideoSurface *> &surfaces);
136
137 QMediaContent media() const;
138 const QIODevice *mediaStream() const;
139 QMediaPlaylist *playlist() const;
140 QMediaContent currentMedia() const;
141
142 State state() const;
143 MediaStatus mediaStatus() const;
144
145 qint64 duration() const;
146 qint64 position() const;
147
148 int volume() const;
149 bool isMuted() const;
150 bool isAudioAvailable() const;
151 bool isVideoAvailable() const;
152
153 int bufferStatus() const;
154
155 bool isSeekable() const;
156 qreal playbackRate() const;
157
158 Error error() const;
159 QString errorString() const;
160
161#ifndef QT_NO_BEARERMANAGEMENT
162QT_WARNING_PUSH
163QT_WARNING_DISABLE_DEPRECATED
164 QT_DEPRECATED_VERSION_5_15 QNetworkConfiguration currentNetworkConfiguration() const;
165QT_WARNING_POP
166#endif
167
168 QMultimedia::AvailabilityStatus availability() const override;
169
170 QAudio::Role audioRole() const;
171 void setAudioRole(QAudio::Role audioRole);
172 QList<QAudio::Role> supportedAudioRoles() const;
173 QString customAudioRole() const;
174 void setCustomAudioRole(const QString &audioRole);
175 QStringList supportedCustomAudioRoles() const;
176
177public Q_SLOTS:
178 void play();
179 void pause();
180 void stop();
181
182 void setPosition(qint64 position);
183 void setVolume(int volume);
184 void setMuted(bool muted);
185
186 void setPlaybackRate(qreal rate);
187
188 void setMedia(const QMediaContent &media, QIODevice *stream = nullptr);
189 void setPlaylist(QMediaPlaylist *playlist);
190
191#ifndef QT_NO_BEARERMANAGEMENT
192#ifndef Q_MOC_RUN // moc fails to parse the expanded macro
193QT_WARNING_PUSH
194QT_WARNING_DISABLE_DEPRECATED
195#endif
196 QT_DEPRECATED_VERSION_5_15 void setNetworkConfigurations(const QList<QNetworkConfiguration> &configurations);
197#ifndef Q_MOC_RUN // moc fails to parse the expanded macro
198QT_WARNING_POP
199#endif
200#endif
201
202Q_SIGNALS:
203 void mediaChanged(const QMediaContent &media);
204 void currentMediaChanged(const QMediaContent &media);
205
206 void stateChanged(QMediaPlayer::State newState);
207 void mediaStatusChanged(QMediaPlayer::MediaStatus status);
208
209 void durationChanged(qint64 duration);
210 void positionChanged(qint64 position);
211
212 void volumeChanged(int volume);
213 void mutedChanged(bool muted);
214 void audioAvailableChanged(bool available);
215 void videoAvailableChanged(bool videoAvailable);
216
217 void bufferStatusChanged(int percentFilled);
218
219 void seekableChanged(bool seekable);
220 void playbackRateChanged(qreal rate);
221
222 void audioRoleChanged(QAudio::Role role);
223 void customAudioRoleChanged(const QString &role);
224
225 void error(QMediaPlayer::Error error);
226
227#ifndef QT_NO_BEARERMANAGEMENT
228#ifndef Q_MOC_RUN // moc fails to parse the expanded macro
229QT_WARNING_PUSH
230QT_WARNING_DISABLE_DEPRECATED
231#endif
232 QT_DEPRECATED_VERSION_5_15 void networkConfigurationChanged(const QNetworkConfiguration &configuration);
233#ifndef Q_MOC_RUN // moc fails to parse the expanded macro
234QT_WARNING_POP
235#endif
236#endif
237public:
238 bool bind(QObject *) override;
239 void unbind(QObject *) override;
240
241private:
242 Q_DISABLE_COPY(QMediaPlayer)
243 Q_DECLARE_PRIVATE(QMediaPlayer)
244 Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaPlayer::State))
245 Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus))
246 Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
247 Q_PRIVATE_SLOT(d_func(), void _q_updateMedia(const QMediaContent&))
248 Q_PRIVATE_SLOT(d_func(), void _q_playlistDestroyed())
249 Q_PRIVATE_SLOT(d_func(), void _q_handleMediaChanged(const QMediaContent&))
250 Q_PRIVATE_SLOT(d_func(), void _q_handlePlaylistLoaded())
251 Q_PRIVATE_SLOT(d_func(), void _q_handlePlaylistLoadFailed())
252};
253
254QT_END_NAMESPACE
255
256Q_DECLARE_METATYPE(QMediaPlayer::State)
257Q_DECLARE_METATYPE(QMediaPlayer::MediaStatus)
258Q_DECLARE_METATYPE(QMediaPlayer::Error)
259
260Q_MEDIA_ENUM_DEBUG(QMediaPlayer, State)
261Q_MEDIA_ENUM_DEBUG(QMediaPlayer, MediaStatus)
262Q_MEDIA_ENUM_DEBUG(QMediaPlayer, Error)
263
264#endif // QMEDIAPLAYER_H
265

source code of qtmultimedia/src/multimedia/playback/qmediaplayer.h