CopperSpice API  1.9.1
QAudioDecoder Class Reference

The QAudioDecoder class allows decoding audio. More...

Inheritance diagram for QAudioDecoder:
QMediaObject QObject

Public Types

enum  Error
 
enum  State
 

Public Signals

void bufferAvailableChanged (bool available)
 
void bufferReady ()
 
void durationChanged (qint64 duration)
 
void error (QAudioDecoder::Error error)
 
void finished ()
 
void formatChanged (const QAudioFormat &format)
 
void positionChanged (qint64 position)
 
void sourceChanged ()
 
void stateChanged (QAudioDecoder::State state)
 
- Public Signals inherited from QMediaObject
void availabilityChanged (bool available)
 
void availabilityChanged (QMultimedia::AvailabilityStatus availability)
 
void metaDataAvailableChanged (bool available)
 
void metaDataChanged ()
 
void metaDataChanged (const QString &key, const QVariant &value)
 
void notifyIntervalChanged (int milliSeconds)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void start ()
 
void stop ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QAudioDecoder (QObject *parent=nullptr)
 
 ~QAudioDecoder ()
 
QAudioFormat audioFormat () const
 
bool bind (QObject *object) override
 
bool bufferAvailable () const
 
qint64 duration () const
 
Error error () const
 
QString errorString () const
 
qint64 position () const
 
QAudioBuffer read () const
 
void setAudioFormat (const QAudioFormat &format)
 
void setSourceDevice (QIODevice *device)
 
void setSourceFilename (const QString &fileName)
 
QIODevicesourceDevice () const
 
QString sourceFilename () const
 
State state () const
 
void unbind (QObject *object) override
 
- Public Methods inherited from QMediaObject
 ~QMediaObject ()
 
virtual QMultimedia::AvailabilityStatus availability () const
 
QStringList availableMetaData () const
 
virtual bool isAvailable () const
 
bool isMetaDataAvailable () const
 
QVariant metaData (const QString &key) const
 
int notifyInterval () const
 
virtual QMediaServiceservice () const
 
void setNotifyInterval (int milliSeconds)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Static Public Methods

static QMultimedia::SupportEstimate hasSupport (const QString &mimeType, const QStringList &codecs=QStringList ())
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Properties

 bufferAvailable
 Whether there is a decoded audio buffer available. More...
 
 error
 String describing the last error condition. More...
 
 sourceFilename
 Active filename being decoded by the decoder object. More...
 
 state
 Audio decoder's playback state. More...
 
- Properties inherited from QMediaObject
 notifyInterval
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Protected Methods inherited from QMediaObject
 QMediaObject (QObject *parent, QMediaService *service)
 
template<typename T >
void addPropertyWatch (const QString &name)
 
void removePropertyWatch (const QString &name)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The QAudioDecoder class is a high level class for decoding local 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, and playlists and network and streaming based media is not supported.

See also
QAudioBuffer

Member Enumeration Documentation

Defines a media player error condition.

Constant Value Description
QAudioDecoder::NoError 0 No error has occurred
QAudioDecoder::ResourceError 1 Media resource could not be resolved
QAudioDecoder::FormatError 2 Format of a media resource is not supported
QAudioDecoder::AccessDeniedError 3 There are not the appropriate permissions to play a media resource
QAudioDecoder::ServiceMissingError 4 Valid playback service was not found, playback cannot proceed

Defines the current state of a media player.

Constant Value Description
QAudioDecoder::StoppedState 0 Decoder is not decoding, will start at the beginning of the media
QAudioDecoder::DecodingState 1 Audio player is currently decoding media

Constructor & Destructor Documentation

QAudioDecoder::QAudioDecoder ( QObject parent = nullptr)
explicit

Construct an QAudioDecoder instance parented to parent.

QAudioDecoder::~QAudioDecoder ( )

Destroys the audio decoder object.

Method Documentation

QAudioFormat QAudioDecoder::audioFormat ( ) const

Returns the current audio format of the decoded stream. Any buffers returned should have this format.

See also
setAudioFormat(), formatChanged()
bool QAudioDecoder::bind ( QObject object)
overridevirtual

Bind object to this QMediaObject instance. This method establishes a relationship between this media object and a helper object. The nature of the relationship depends on both parties. This methods returns true if the helper was successfully bound, false otherwise.

Most subclasses of QMediaObject provide more convenient functions that wrap this functionality so this function rarely needs to be called directly.

The object passed must implement the QMediaBindableInterface interface.

See also
QMediaBindableInterface

Reimplemented from QMediaObject::bind()

bool QAudioDecoder::bufferAvailable ( ) const

Returns true if a buffer is available to be read, and false otherwise. If there is no buffer available, calling read() will return an invalid buffer.

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()
void QAudioDecoder::bufferReady ( )
signal

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

See also
read(), bufferAvailable()
qint64 QAudioDecoder::duration ( ) const

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

void QAudioDecoder::durationChanged ( qint64  duration)
signal

Signals the estimated duration of the decoded data has changed.

See also
positionChanged()
QAudioDecoder::Error QAudioDecoder::error ( ) const

Returns the current error state.

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

Signals an error condition has occurred.

See also
errorString()
QString QAudioDecoder::errorString ( ) const

Return the value of the error property.

void QAudioDecoder::finished ( )
signal

Signals the decoding has finished successfully. If decoding fails, error signal is emitted instead.

See also
start(), stop(), error()
void QAudioDecoder::formatChanged ( const QAudioFormat format)
signal

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

See also
audioFormat(), setAudioFormat()
QMultimedia::SupportEstimate QAudioDecoder::hasSupport ( const QString mimeType,
const QStringList codecs = QStringList() 
)
static

Returns the level of support an audio decoder has for a mimeType and a set of codecs.

qint64 QAudioDecoder::position ( ) const

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

void QAudioDecoder::positionChanged ( qint64  position)
signal

Signals the current position of the decoder has changed.

See also
durationChanged()
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 bufferReady() signal or check the bufferAvailable() methods before calling read() to make sure you get useful data.

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, 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.

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.

void QAudioDecoder::setSourceFilename ( const QString 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.

void QAudioDecoder::sourceChanged ( )
signal

Signals the current source of the decoder has changed.

See also
sourceFilename(), sourceDevice()
QIODevice * QAudioDecoder::sourceDevice ( ) const

Returns the current source QIODevice, if one was set. If setSourceFilename() was called, this will be 0.

QString QAudioDecoder::sourceFilename ( ) const

Returns the current file name to decode. If setSourceDevice() was called there is no file name so the return value will be an empty string.

void QAudioDecoder::start ( )
slot

Starts decoding the audio resource.

As data gets decoded, the bufferReady() signal will be emitted when enough data has been decoded. Calling 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()
State QAudioDecoder::state ( ) const

Returns the audio decoder's playback state.

void QAudioDecoder::stateChanged ( QAudioDecoder::State  state)
signal

Signal the state of the decoder object has changed.

void QAudioDecoder::stop ( )
slot

Stop decoding audio. Calling start() again will resume decoding from the beginning.

void QAudioDecoder::unbind ( QObject object)
overridevirtual

Detach object from the QMediaObject instance. Unbind the helper object from this media object. A warning will be generated if the object was not previously bound to this object.

See also
QMediaBindableInterface

Reimplemented from QMediaObject::unbind()

Property Documentation

QAudioDecoder::bufferAvailable

This property stores whether there is a decoded audio buffer available.

PropertiesClass Methods
read bufferAvailable
notify bufferAvailableChanged
QAudioDecoder::error

This property stores a string describing the last error condition.

See also
error()
PropertiesClass Methods
read errorString
QAudioDecoder::sourceFilename

This property stores the active filename being decoded by the decoder object.

PropertiesClass Methods
read sourceFilename
write setSourceFilename
notify sourceChanged
QAudioDecoder::state

This property stores the audio decoder's playback state. By default this property is QAudioDecoder::Stopped

See also
start(), stop()
PropertiesClass Methods
read state
notify stateChanged