![]() |
Qt 6.x
The Qt SDK
|
The QAudioDecoder class implements decoding audio. More...
#include <qaudiodecoder.h>
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. | |
![]() | |
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. | |
![]() | |
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. | |
QIODevice * | sourceDevice () 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. | |
![]() | |
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< QString > | bindableObjectName () |
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). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
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::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), 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 (const QString &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 > | |
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 QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () 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 | |
![]() | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
![]() | |
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) |
![]() | |
QObject * | sender () 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) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
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.
Definition at line 15 of file qaudiodecoder.h.
enum QAudioDecoder::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 24 of file qaudiodecoder.h.
Construct an QAudioDecoder instance with parent.
Definition at line 41 of file qaudiodecoder.cpp.
References QPlatformMediaIntegration::createAudioDecoder(), QPlatformMediaIntegration::instance(), and qWarning.
|
default |
Destroys the audio decoder object.
QAudioFormat QAudioDecoder::audioFormat | ( | ) | const |
Returns the audio format the decoder is set to.
Definition at line 188 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::audioFormat().
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 227 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::bufferAvailable().
|
signal |
Signals the availability (if available is true) of a new buffer.
If available is false, there are no buffers available.
|
signal |
Signals that a new decoded audio buffer is available to be read.
Referenced by AudioDecodingExample::decode(), and QAmbientSoundPrivate::load().
qint64 QAudioDecoder::duration | ( | ) | const |
Returns total duration (in milliseconds) of the audio stream or -1 if not available.
Definition at line 247 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::duration().
Signals that the estimated duration of the decoded data has changed.
QAudioDecoder::Error QAudioDecoder::error | ( | ) | const |
Returns the current error state of the QAudioDecoder.
Definition at line 79 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::error(), and NotSupportedError.
|
signal |
Signals that an error condition has occurred.
QString QAudioDecoder::errorString | ( | ) | const |
Definition at line 90 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::errorString(), and tr.
|
signal |
Signals that the decoding has finished successfully.
If decoding fails, error signal is emitted instead.
Referenced by QAmbientSoundPrivate::load().
|
signal |
Signals that the current audio format of the decoder has changed to format.
bool QAudioDecoder::isDecoding | ( | ) | const |
Definition at line 70 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::isDecoding().
|
signal |
bool QAudioDecoder::isSupported | ( | ) | const |
Returns true is audio decoding is supported on this platform.
Definition at line 61 of file qaudiodecoder.cpp.
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 237 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::position().
Signals that the current position of the decoder has changed.
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 262 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::read().
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.
Definition at line 213 of file qaudiodecoder.cpp.
References isDecoding, and QPlatformAudioDecoder::setAudioFormat().
Referenced by AudioDecodingExample::decode().
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 147 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::clearError(), fileName, and QPlatformAudioDecoder::setSource().
Referenced by AudioDecodingExample::decode().
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 174 of file qaudiodecoder.cpp.
References device, and QPlatformAudioDecoder::setSourceDevice().
QUrl QAudioDecoder::source | ( | ) | const |
Returns the current file name to decode.
If \l setSourceDevice was called, this will be empty.
Definition at line 133 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::source().
|
signal |
Signals that the current source of the decoder has changed.
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 160 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::sourceDevice().
|
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.
Definition at line 109 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::clearError(), and QPlatformAudioDecoder::start().
Referenced by AudioDecodingExample::decode().
|
slot |
Stop decoding audio.
Calling \l start() again will resume decoding from the beginning.
Definition at line 122 of file qaudiodecoder.cpp.
References QPlatformAudioDecoder::stop().
|
read |
whether there is a decoded audio buffer available
Definition at line 82 of file qaudiodecoder.h.
|
read |
Returns a human readable description of the current error, or an empty string is there is no error.
Definition at line 82 of file qaudiodecoder.h.
|
read |
true
if the decoder is currently running and decoding audio data.
Definition at line 82 of file qaudiodecoder.h.
Referenced by setAudioFormat().
|
readwrite |
the active filename being decoded by the decoder object.
Definition at line 82 of file qaudiodecoder.h.