Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmediaplayer.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMEDIAPLAYER_H
5#define QMEDIAPLAYER_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qurl.h>
9#include <QtMultimedia/qtmultimediaglobal.h>
10#include <QtMultimedia/qmediaenumdebug.h>
11#include <QtMultimedia/qtaudio.h>
12
14
15class QVideoSink;
16class QAudioOutput;
17class QAudioDevice;
18class QMediaMetaData;
19class QMediaTimeRange;
20
22class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QObject
23{
25 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
26 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
27 Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged)
28 Q_PROPERTY(float bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
29 Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
30 Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
31 Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
32 Q_PROPERTY(bool playing READ isPlaying NOTIFY playingChanged)
33 Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
34 Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
35 Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
36 Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
37 Q_PROPERTY(QMediaMetaData metaData READ metaData NOTIFY metaDataChanged)
38 Q_PROPERTY(Error error READ error NOTIFY errorChanged)
39 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
40 Q_PROPERTY(QObject *videoOutput READ videoOutput WRITE setVideoOutput NOTIFY videoOutputChanged)
41 Q_PROPERTY(QAudioOutput *audioOutput READ audioOutput WRITE setAudioOutput NOTIFY
42 audioOutputChanged)
43
44 Q_PROPERTY(QList<QMediaMetaData> audioTracks READ audioTracks NOTIFY tracksChanged)
45 Q_PROPERTY(QList<QMediaMetaData> videoTracks READ videoTracks NOTIFY tracksChanged)
46 Q_PROPERTY(QList<QMediaMetaData> subtitleTracks READ subtitleTracks NOTIFY tracksChanged)
47
48 Q_PROPERTY(int activeAudioTrack READ activeAudioTrack WRITE setActiveAudioTrack NOTIFY
49 activeTracksChanged)
50 Q_PROPERTY(int activeVideoTrack READ activeVideoTrack WRITE setActiveVideoTrack NOTIFY
51 activeTracksChanged)
52 Q_PROPERTY(int activeSubtitleTrack READ activeSubtitleTrack WRITE setActiveSubtitleTrack NOTIFY
53 activeTracksChanged)
54
55public:
57 {
60 PausedState
61 };
62 Q_ENUM(PlaybackState)
63
75 Q_ENUM(MediaStatus)
76
77 enum Error
78 {
83 AccessDeniedError
84 };
86
87 enum Loops
88 {
89 Infinite = -1,
90 Once = 1
91 };
92 Q_ENUM(Loops)
93
94 explicit QMediaPlayer(QObject *parent = nullptr);
96
97 QList<QMediaMetaData> audioTracks() const;
98 QList<QMediaMetaData> videoTracks() const;
99 QList<QMediaMetaData> subtitleTracks() const;
100
101 int activeAudioTrack() const;
102 int activeVideoTrack() const;
103 int activeSubtitleTrack() const;
104
105 void setActiveAudioTrack(int index);
106 void setActiveVideoTrack(int index);
107 void setActiveSubtitleTrack(int index);
108
109 void setAudioOutput(QAudioOutput *output);
110 QAudioOutput *audioOutput() const;
111
112 void setVideoOutput(QObject *);
113 QObject *videoOutput() const;
114
115 void setVideoSink(QVideoSink *sink);
116 QVideoSink *videoSink() const;
117
118 QUrl source() const;
119 const QIODevice *sourceDevice() const;
120
121 PlaybackState playbackState() const;
122 MediaStatus mediaStatus() const;
123
124 qint64 duration() const;
125 qint64 position() const;
126
127 bool hasAudio() const;
128 bool hasVideo() const;
129
130 float bufferProgress() const;
131 QMediaTimeRange bufferedTimeRange() const;
132
133 bool isSeekable() const;
134 qreal playbackRate() const;
135
136 bool isPlaying() const;
137
138 int loops() const;
139 void setLoops(int loops);
140
141 Error error() const;
142 QString errorString() const;
143
144 bool isAvailable() const;
145 QMediaMetaData metaData() const;
146
147public Q_SLOTS:
148 void play();
149 void pause();
150 void stop();
151
153
154 void setPlaybackRate(qreal rate);
155
156 void setSource(const QUrl &source);
157 void setSourceDevice(QIODevice *device, const QUrl &sourceUrl = QUrl());
158
160 void sourceChanged(const QUrl &media);
163
164 void durationChanged(qint64 duration);
166
167 void hasAudioChanged(bool available);
168 void hasVideoChanged(bool videoAvailable);
169
170 void bufferProgressChanged(float progress);
171
172 void seekableChanged(bool seekable);
173 void playingChanged(bool playing);
176
180
183
186
187private:
188 Q_DISABLE_COPY(QMediaPlayer)
189 Q_DECLARE_PRIVATE(QMediaPlayer)
191};
192
194
198
199#endif // QMEDIAPLAYER_H
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
\qmltype AudioOutput \instantiates QAudioOutput
\inmodule QtCore \reentrant
Definition qiodevice.h:34
Definition qlist.h:75
\inmodule QtMultimedia
The QMediaPlayer class allows the playing of a media files.
void durationChanged(qint64 duration)
Signals the duration of the content has changed to duration, expressed in milliseconds.
void errorChanged()
void metaDataChanged()
void sourceChanged(const QUrl &media)
Signals that the media source has been changed to media.
void hasAudioChanged(bool available)
Signals the availability of audio content has changed to available.
void errorOccurred(QMediaPlayer::Error error, const QString &errorString)
\qmlsignal QtMultimedia::MediaPlayer::errorOccurred(error, errorString)
void positionChanged(qint64 position)
Signals the position of the content has changed to position, expressed in milliseconds.
MediaStatus
\qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState
void playingChanged(bool playing)
void seekableChanged(bool seekable)
Signals the seekable status of the player object has changed.
void audioOutputChanged()
void bufferProgressChanged(float progress)
Signals the amount of the local buffer filled as a number between 0 and 1.
PlaybackState
Defines the current state of a media player.
void activeTracksChanged()
void videoOutputChanged()
Loops
Some predefined constants for the \l loops property.
void playbackStateChanged(QMediaPlayer::PlaybackState newState)
void tracksChanged()
Error
\qmlproperty enumeration QtMultimedia::MediaPlayer::mediaStatus
void hasVideoChanged(bool videoAvailable)
Signals the availability of visual content has changed to videoAvailable.
void loopsChanged()
void playbackRateChanged(qreal rate)
Signals the playbackRate has changed to rate.
void mediaStatusChanged(QMediaPlayer::MediaStatus status)
Signals that the status of the current media has changed.
The QMediaTimeRange class represents a set of zero or more disjoint time intervals.
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define Q_MEDIA_ENUM_DEBUG(Class, Enum)
n void setPosition(void) \n\
GLuint index
[2]
GLsizei GLsizei GLchar * source
GLuint GLenum * rate
GLsizei GLenum GLboolean sink
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
QT_BEGIN_NAMESPACE typedef uchar * output