Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QAudioDecoder Class Reference

The QAudioDecoder class implements decoding audio. More...

#include <qaudiodecoder.h>

+ Inheritance diagram for QAudioDecoder:
+ Collaboration diagram for QAudioDecoder:

Public Types

enum  Error {
  NoError , ResourceError , FormatError , AccessDeniedError ,
  NotSupportedError
}
 Defines a media player error condition. More...
 

Public Slots

void start ()
 Starts decoding the audio resource.
 
void stop ()
 Stop decoding audio.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void bufferAvailableChanged (bool)
 Signals the availability (if available is true) of a new buffer.
 
void bufferReady ()
 Signals that a new decoded audio buffer is available to be read.
 
void finished ()
 Signals that the decoding has finished successfully.
 
void isDecodingChanged (bool)
 
void formatChanged (const QAudioFormat &format)
 Signals that the current audio format of the decoder has changed to format.
 
void error (QAudioDecoder::Error error)
 Signals that an error condition has occurred.
 
void sourceChanged ()
 Signals that the current source of the decoder has changed.
 
void positionChanged (qint64 position)
 Signals that the current position of the decoder has changed.
 
void durationChanged (qint64 duration)
 Signals that the estimated duration of the decoded data has changed.
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QAudioDecoder (QObject *parent=nullptr)
 Construct an QAudioDecoder instance with parent.
 
 ~QAudioDecoder ()
 Destroys the audio decoder object.
 
bool isSupported () const
 Returns true is audio decoding is supported on this platform.
 
bool isDecoding () const
 
QUrl source () const
 Returns the current file name to decode.
 
void setSource (const QUrl &fileName)
 Sets the current audio file name to fileName.
 
QIODevicesourceDevice () const
 Returns the current source QIODevice, if one was set.
 
void setSourceDevice (QIODevice *device)
 Sets the current audio QIODevice to device.
 
QAudioFormat audioFormat () const
 Returns the audio format the decoder is set to.
 
void setAudioFormat (const QAudioFormat &format)
 Set the desired audio format for decoded samples to format.
 
Error error () const
 Returns the current error state of the QAudioDecoder.
 
QString errorString () const
 
QAudioBuffer read () const
 Read a buffer from the decoder, if one is available.
 
bool bufferAvailable () const
 Returns true if a buffer is available to be read, and false otherwise.
 
qint64 position () const
 Returns position (in milliseconds) of the last buffer read from the decoder or -1 if no buffers have been read.
 
qint64 duration () const
 Returns total duration (in milliseconds) of the audio stream or -1 if not available.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Properties

QUrl source
 the active filename being decoded by the decoder object.
 
bool isDecoding
 true if the decoder is currently running and decoding audio data.
 
QString error
 Returns a human readable description of the current error, or an empty string is there is no error.
 
bool bufferAvailable
 whether there is a decoded audio buffer available
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

The QAudioDecoder class implements decoding audio.

\inmodule QtMultimedia

\preliminary

The QAudioDecoder class is a high level class for decoding audio media files. It is similar to the QMediaPlayer class except that audio is provided back through this API rather than routed directly to audio hardware.

See also
QAudioBuffer

Definition at line 13 of file qaudiodecoder.h.

Member Enumeration Documentation

◆ Error

Defines a media player error condition.

\value NoError No error has occurred. \value ResourceError A media resource couldn't be resolved. \value FormatError The format of a media resource isn't supported. \value AccessDeniedError There are not the appropriate permissions to play a media resource. \value NotSupportedError QAudioDecoder is not supported on this platform

Enumerator
NoError 
ResourceError 
FormatError 
AccessDeniedError 
NotSupportedError 

Definition at line 22 of file qaudiodecoder.h.

Constructor & Destructor Documentation

◆ QAudioDecoder()

QAudioDecoder::QAudioDecoder ( QObject * parent = nullptr)
explicit

Construct an QAudioDecoder instance with parent.

Definition at line 40 of file qaudiodecoder.cpp.

◆ ~QAudioDecoder()

QAudioDecoder::~QAudioDecoder ( )
default

Destroys the audio decoder object.

Member Function Documentation

◆ audioFormat()

QAudioFormat QAudioDecoder::audioFormat ( ) const

Returns the audio format the decoder is set to.

Note
This may be different than the format of the decoded samples, if the audio format was set to an invalid one.
See also
setAudioFormat(), formatChanged()

Definition at line 209 of file qaudiodecoder.cpp.

◆ bufferAvailable()

bool QAudioDecoder::bufferAvailable ( ) const

Returns true if a buffer is available to be read, and false otherwise.

If there is no buffer available, calling the \l read() function will return an invalid buffer.

Definition at line 251 of file qaudiodecoder.cpp.

◆ bufferAvailableChanged

void QAudioDecoder::bufferAvailableChanged ( bool available)
signal

Signals the availability (if available is true) of a new buffer.

If available is false, there are no buffers available.

See also
bufferAvailable(), bufferReady()

◆ bufferReady

void QAudioDecoder::bufferReady ( )
signal

Signals that a new decoded audio buffer is available to be read.

See also
read(), bufferAvailable()

◆ duration()

qint64 QAudioDecoder::duration ( ) const

Returns total duration (in milliseconds) of the audio stream or -1 if not available.

Definition at line 273 of file qaudiodecoder.cpp.

◆ durationChanged

void QAudioDecoder::durationChanged ( qint64 duration)
signal

Signals that the estimated duration of the decoded data has changed.

See also
positionChanged()

◆ error() [1/2]

QAudioDecoder::Error QAudioDecoder::error ( ) const

Returns the current error state of the QAudioDecoder.

Definition at line 84 of file qaudiodecoder.cpp.

◆ error [2/2]

void QAudioDecoder::error ( QAudioDecoder::Error error)
signal

Signals that an error condition has occurred.

See also
errorString()

◆ errorString()

QString QAudioDecoder::errorString ( ) const

Definition at line 96 of file qaudiodecoder.cpp.

◆ finished

void QAudioDecoder::finished ( )
signal

Signals that the decoding has finished successfully.

If decoding fails, error signal is emitted instead.

See also
start(), stop(), error()

◆ formatChanged

void QAudioDecoder::formatChanged ( const QAudioFormat & format)
signal

Signals that the current audio format of the decoder has changed to format.

See also
audioFormat(), setAudioFormat()

◆ isDecoding()

bool QAudioDecoder::isDecoding ( ) const

Definition at line 73 of file qaudiodecoder.cpp.

◆ isDecodingChanged

void QAudioDecoder::isDecodingChanged ( bool )
signal

◆ isSupported()

bool QAudioDecoder::isSupported ( ) const

Returns true is audio decoding is supported on this platform.

Definition at line 62 of file qaudiodecoder.cpp.

◆ position()

qint64 QAudioDecoder::position ( ) const

Returns position (in milliseconds) of the last buffer read from the decoder or -1 if no buffers have been read.

Definition at line 262 of file qaudiodecoder.cpp.

◆ positionChanged

void QAudioDecoder::positionChanged ( qint64 position)
signal

Signals that the current position of the decoder has changed.

See also
durationChanged()

◆ read()

QAudioBuffer QAudioDecoder::read ( ) const

Read a buffer from the decoder, if one is available.

Returns an invalid buffer if there are no decoded buffers currently available, or on failure. In both cases this function will not block.

You should either respond to the \l bufferReady() signal or check the \l bufferAvailable() function before calling read() to make sure you get useful data.

Definition at line 289 of file qaudiodecoder.cpp.

◆ setAudioFormat()

void QAudioDecoder::setAudioFormat ( const QAudioFormat & format)

Set the desired audio format for decoded samples to format.

This property can only be set while the decoder is stopped. Setting this property at other times will be ignored.

If the decoder does not support this format, \l error() will be set to FormatError.

If you do not specify a format, the format of the decoded audio itself will be used. Otherwise, some format conversion will be applied.

If you wish to reset the decoded format to that of the original audio file, you can specify an invalid format.

Warning
Setting a desired audio format is not yet supported on the Android backend. It does work with the default FFMPEG backend.

Definition at line 235 of file qaudiodecoder.cpp.

◆ setSource()

void QAudioDecoder::setSource ( const QUrl & fileName)

Sets the current audio file name to fileName.

When this property is set any current decoding is stopped, and any audio buffers are discarded.

You can only specify either a source filename or a source QIODevice. Setting one will unset the other.

Definition at line 159 of file qaudiodecoder.cpp.

◆ setSourceDevice()

void QAudioDecoder::setSourceDevice ( QIODevice * device)

Sets the current audio QIODevice to device.

When this property is set any current decoding is stopped, and any audio buffers are discarded.

You can only specify either a source filename or a source QIODevice. Setting one will unset the other.

Definition at line 192 of file qaudiodecoder.cpp.

◆ source()

QUrl QAudioDecoder::source ( ) const

Returns the current file name to decode.

If \l setSourceDevice was called, this will be empty.

Definition at line 144 of file qaudiodecoder.cpp.

◆ sourceChanged

void QAudioDecoder::sourceChanged ( )
signal

Signals that the current source of the decoder has changed.

See also
source(), sourceDevice()

◆ sourceDevice()

QIODevice * QAudioDecoder::sourceDevice ( ) const

Returns the current source QIODevice, if one was set.

If \l setSource() was called, this will be a nullptr.

Definition at line 177 of file qaudiodecoder.cpp.

◆ start

void QAudioDecoder::start ( )
slot

Starts decoding the audio resource.

As data gets decoded, the \l bufferReady() signal will be emitted when enough data has been decoded. Calling \l read() will then return an audio buffer without blocking.

If you call read() before a buffer is ready, an invalid buffer will be returned, again without blocking.

See also
read()

Definition at line 116 of file qaudiodecoder.cpp.

◆ stop

void QAudioDecoder::stop ( )
slot

Stop decoding audio.

Calling \l start() again will resume decoding from the beginning.

Definition at line 131 of file qaudiodecoder.cpp.

Property Documentation

◆ bufferAvailable

bool QAudioDecoder::bufferAvailable
read

whether there is a decoded audio buffer available

Definition at line 19 of file qaudiodecoder.h.

◆ error

QString QAudioDecoder::error
read

Returns a human readable description of the current error, or an empty string is there is no error.

Definition at line 18 of file qaudiodecoder.h.

◆ isDecoding

bool QAudioDecoder::isDecoding
read

true if the decoder is currently running and decoding audio data.

Definition at line 17 of file qaudiodecoder.h.

◆ source

QUrl QAudioDecoder::source
readwrite

the active filename being decoded by the decoder object.

Definition at line 16 of file qaudiodecoder.h.


The documentation for this class was generated from the following files: