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
qaudiodecoder.cpp
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#include "qaudiodecoder.h"
5
6#include <private/qaudiodecoder_p.h>
7#include <private/qmultimediautils_p.h>
8#include <private/qplatformaudiodecoder_p.h>
9#include <private/qplatformmediaintegration_p.h>
10
11#include <QtCore/qcoreevent.h>
12#include <QtCore/qdebug.h>
13#include <QtCore/qmetaobject.h>
14#include <QtCore/qpointer.h>
15#include <QtCore/qtimer.h>
16#include <QtCore/qurl.h>
17
19
41{
42 QT6_ONLY(Q_UNUSED(unused))
43
44 Q_D(QAudioDecoder);
45
46 auto maybeDecoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this);
47 if (maybeDecoder) {
48 d->decoder.reset(maybeDecoder.value());
49 } else {
50 qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error();
51 }
52}
53
58
63{
64 Q_D(const QAudioDecoder);
65
66 return bool(d->decoder);
67}
68
74{
75 Q_D(const QAudioDecoder);
76
77 return d->decoder && d->decoder->isDecoding();
78}
79
85{
86 Q_D(const QAudioDecoder);
87 return d->decoder ? d->decoder->error() : NotSupportedError;
88}
89
97{
98 Q_D(const QAudioDecoder);
99 if (!d->decoder)
100 return tr("QAudioDecoder not supported.");
101 return d->decoder->errorString();
102}
103
117{
118 Q_D(QAudioDecoder);
119
120 if (!d->decoder)
121 return;
122
123 // Reset error conditions
124 d->decoder->clearError();
125 d->decoder->start();
126}
127
132{
133 Q_D(QAudioDecoder);
134
135 if (d->decoder)
136 d->decoder->stop();
137}
138
145{
146 Q_D(const QAudioDecoder);
147 return d->unresolvedUrl;
148}
149
160{
161 Q_D(QAudioDecoder);
162
163 if (!d->decoder)
164 return;
165
166 d->decoder->clearError();
167 d->unresolvedUrl = fileName;
168 d->decoder->setSourceDevice(nullptr);
170 d->decoder->setSource(url);
171}
172
178{
179 Q_D(const QAudioDecoder);
180 return d->decoder ? d->decoder->sourceDevice() : nullptr;
181}
182
193{
194 Q_D(QAudioDecoder);
195 if (d->decoder) {
196 d->unresolvedUrl = QUrl{};
197 d->decoder->setSourceDevice(device);
198 }
199}
200
210{
211 Q_D(const QAudioDecoder);
212 return d->decoder ? d->decoder->audioFormat() : QAudioFormat{};
213}
214
236{
237 if (isDecoding())
238 return;
239
240 Q_D(QAudioDecoder);
241
242 if (d->decoder)
243 d->decoder->setAudioFormat(format);
244}
245
252{
253 Q_D(const QAudioDecoder);
254 return d->decoder && d->decoder->bufferAvailable();
255}
256
263{
264 Q_D(const QAudioDecoder);
265 return d->decoder ? d->decoder->position() : -1;
266}
267
274{
275 Q_D(const QAudioDecoder);
276 return d->decoder ? d->decoder->duration() : -1;
277}
278
290{
291 Q_D(const QAudioDecoder);
292 return d->decoder ? d->decoder->read() : QAudioBuffer{};
293}
294
295// Enums
308// Signals
376// Properties
388
389#include "moc_qaudiodecoder.cpp"
IOBluetoothDevice * device
\inmodule QtMultimedia
The QAudioDecoder class implements decoding audio.
QString errorString() const
QAudioBuffer read() const
Read a buffer from the decoder, if one is available.
QAudioFormat audioFormat() const
Returns the audio format the decoder is set to.
void stop()
Stop decoding audio.
void start()
Starts decoding the audio resource.
bool isDecoding
true if the decoder is currently running and decoding audio data.
qint64 duration() const
Returns total duration (in milliseconds) of the audio stream or -1 if not available.
Error
Defines a media player error condition.
void setSource(const QUrl &fileName)
Sets the current audio file name to fileName.
void setAudioFormat(const QAudioFormat &format)
Set the desired audio format for decoded samples to format.
void setSourceDevice(QIODevice *device)
Sets the current audio QIODevice to device.
~QAudioDecoder()
Destroys the audio decoder object.
bool bufferAvailable
whether there is a decoded audio buffer available
QIODevice * sourceDevice() const
Returns the current source QIODevice, if one was set.
qint64 position() const
Returns position (in milliseconds) of the last buffer read from the decoder or -1 if no buffers have ...
bool isSupported() const
Returns true is audio decoding is supported on this platform.
QAudioDecoder(QObject *parent=nullptr)
Construct an QAudioDecoder instance with parent.
QString error
Returns a human readable description of the current error, or an empty string is there is no error.
QUrl source
the active filename being decoded by the decoder object.
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:103
static QPlatformMediaIntegration * instance()
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
class QT6_ONLY(Q_CORE_EXPORT) QChar
Definition qchar.h:44
#define qWarning
Definition qlogging.h:166
QUrl qMediaFromUserInput(QUrl url)
GLint GLsizei GLsizei GLenum format
#define tr(X)
#define Q_UNUSED(x)
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]