Qt 6.x
The Qt SDK
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
5#include "qaudiodecoder.h"
6
7#include "private/qplatformaudiodecoder_p.h"
8
9#include <private/qplatformmediaintegration_p.h>
10#include <private/qobject_p.h>
11
12#include <QtCore/qcoreevent.h>
13#include <QtCore/qmetaobject.h>
14#include <QtCore/qtimer.h>
15#include <QtCore/qurl.h>
16#include <QtCore/qdebug.h>
17#include <QtCore/qpointer.h>
18
20
43{
45 if (maybeDecoder) {
46 decoder = maybeDecoder.value();
47 } else {
48 qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error();
49 }
50}
51
52
57
62{
63 return bool(decoder);
64}
65
71{
72 return decoder && decoder->isDecoding();
73}
74
80{
81 return decoder ? decoder->error() : NotSupportedError;
82}
83
91{
92 if (!decoder)
93 return tr("QAudioDecoder not supported.");
94 return decoder->errorString();
95}
96
110{
111 if (!decoder)
112 return;
113
114 // Reset error conditions
115 decoder->clearError();
116 decoder->start();
117}
118
123{
124 if (decoder)
125 decoder->stop();
126}
127
134{
135 return decoder ? decoder->source() : QString{};
136}
137
148{
149 if (!decoder)
150 return;
151
152 decoder->clearError();
153 decoder->setSource(fileName);
154}
155
161{
162 return decoder ? decoder->sourceDevice() : nullptr;
163}
164
175{
176 if (decoder)
177 decoder->setSourceDevice(device);
178}
179
189{
190 return decoder ? decoder->audioFormat() : QAudioFormat{};
191}
192
214{
215 if (isDecoding())
216 return;
217
218 if (decoder)
219 decoder->setAudioFormat(format);
220}
221
228{
229 return decoder && decoder->bufferAvailable();
230}
231
238{
239 return decoder ? decoder->position() : -1;
240}
241
248{
249 return decoder ? decoder->duration() : -1;
250}
251
263{
264 return decoder ? decoder->read() : QAudioBuffer{};
265}
266
267// Enums
280// Signals
349// Properties
361
362#include "moc_qaudiodecoder.cpp"
IOBluetoothDevice * device
\inmodule QtMultimedia
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:90
virtual void setSource(const QUrl &fileName)=0
virtual qint64 position() const
virtual QAudioFormat audioFormat() const =0
virtual QUrl source() const =0
void error(int error, const QString &errorString)
virtual QIODevice * sourceDevice() const =0
virtual qint64 duration() const
virtual void setSourceDevice(QIODevice *device)=0
virtual void setAudioFormat(const QAudioFormat &format)=0
virtual bool bufferAvailable() const
virtual void start()=0
virtual void stop()=0
virtual QAudioBuffer read()=0
virtual QMaybe< QPlatformAudioDecoder * > createAudioDecoder(QAudioDecoder *)
static QPlatformMediaIntegration * instance()
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:162
GLint GLsizei GLsizei GLenum format
#define tr(X)
long long qint64
Definition qtypes.h:55
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent