QAudioDecoder 类实现解码音频。 更多...
头: | #include <QAudioDecoder> |
CMake: |
find_package(Qt6 COMPONENTS Multimedia REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
继承: | QObject |
该类在开发且可能改变。
enum | Error { NoError, ResourceError, FormatError, AccessDeniedError, NotSupportedError } |
QAudioDecoder (QObject * parent = nullptr) | |
virtual | ~QAudioDecoder () |
QAudioFormat | audioFormat () const |
bool | bufferAvailable () const |
qint64 | duration () const |
QString | errorString () const |
bool | isDecoding () const |
bool | isSupported () const |
qint64 | position () const |
QAudioBuffer | read () const |
void | setAudioFormat (const QAudioFormat & format ) |
void | setSource (const QUrl & fileName ) |
void | setSourceDevice (QIODevice * device ) |
QUrl | source () const |
QIODevice * | sourceDevice () const |
void | start () |
void | stop () |
void | bufferAvailableChanged (bool available ) |
void | bufferReady () |
void | durationChanged (qint64 duration ) |
void | error (QAudioDecoder::Error error ) |
void | finished () |
void | formatChanged (const QAudioFormat & format ) |
void | isDecodingChanged (bool) |
void | positionChanged (qint64 position ) |
void | sourceChanged () |
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.
另请参阅 QAudioBuffer .
定义媒体播放器错误条件。
常量 | 值 | 描述 |
---|---|---|
QAudioDecoder::NoError
|
0
|
没有出现错误。 |
QAudioDecoder::ResourceError
|
1
|
无法解析媒体资源。 |
QAudioDecoder::FormatError
|
2
|
媒体资源格式不支持。 |
QAudioDecoder::AccessDeniedError
|
3
|
没有适当权限来播放媒体资源。 |
QAudioDecoder::NotSupportedError
|
4
|
QAudioDecoder 不支持在此平台 |
[read-only]
bufferAvailable
: const
bool
This property holds whether there is a decoded audio buffer available
访问函数:
bool | bufferAvailable () const |
通知程序信号:
void | bufferAvailableChanged (bool available ) |
[read-only]
error
: const
QString
此特性保持当前错误状态。
访问函数:
QString | errorString () const |
[read-only]
isDecoding
: const
bool
true
if the decoder is currently running and decoding audio data.
访问函数:
bool | isDecoding () const |
通知程序信号:
void | isDecodingChanged (bool) |
This property holds the active filename being decoded by the decoder object.
访问函数:
QUrl | source () const |
void | setSource (const QUrl & fileName ) |
通知程序信号:
void | sourceChanged () |
构造 QAudioDecoder 实例采用 parent .
[signal]
void
QAudioDecoder::
bufferAvailableChanged
(
bool
available
)
Signals the availability (if available is true) of a new buffer.
若 available is false, there are no buffers available.
注意: 通知程序信号对于特性 bufferAvailable .
另请参阅 bufferAvailable () 和 bufferReady ().
[signal]
void
QAudioDecoder::
bufferReady
()
Signals that a new decoded audio buffer is available to be read.
另请参阅 read () 和 bufferAvailable ().
[signal]
void
QAudioDecoder::
durationChanged
(
qint64
duration
)
Signals that the estimated duration of the decoded data has changed.
另请参阅 positionChanged ().
[signal]
void
QAudioDecoder::
error
(
QAudioDecoder::Error
error
)
Signals that an error 条件已发生。
注意: 信号 error 在此类中被重载。通过使用函数指针句法连接到此信号,Qt 提供用于获得如此范例展示的函数指针的方便帮助程序:
connect(audioDecoder, QOverload<QAudioDecoder::Error>::of(&QAudioDecoder::error), [=](QAudioDecoder::Error error){ /* ... */ });
另请参阅 errorString ().
[signal]
void
QAudioDecoder::
finished
()
Signals that the decoding has finished successfully. If decoding fails, error signal is emitted instead.
另请参阅 start (), stop (),和 error ().
[signal]
void
QAudioDecoder::
formatChanged
(const
QAudioFormat
&
format
)
Signals that the current audio format of the decoder has changed to format .
另请参阅 audioFormat () 和 setAudioFormat ().
[signal]
void
QAudioDecoder::
positionChanged
(
qint64
position
)
Signals that the current position of the decoder has changed.
另请参阅 durationChanged ().
[signal]
void
QAudioDecoder::
sourceChanged
()
Signals that the current source of the decoder has changed.
注意: 通知程序信号对于特性 source .
另请参阅 source () 和 sourceDevice ().
[slot]
void
QAudioDecoder::
start
()
开始解码音频资源。
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.
若调用 read () before a buffer is ready, an invalid buffer will be returned, again without blocking.
另请参阅 read ().
[slot]
void
QAudioDecoder::
stop
()
停止解码音频。调用 start () again will resume decoding from the beginning.
[虚拟]
QAudioDecoder::
~QAudioDecoder
()
销毁音频解码器对象。
Returns the audio format the decoder is set to.
注意: This may be different than the format of the decoded samples, if the audio format was set to an invalid one.
另请参阅 setAudioFormat () 和 formatChanged ().
Returns true if a buffer is available to be read, and false otherwise. If there is no buffer available, calling the read () function will return an invalid buffer.
注意: getter 函数对于特性 bufferAvailable。
Returns total duration (in milliseconds) of the audio stream or -1 if not available.
Returns a human readable description of the current error, or an empty string is there is no error.
注意: getter 函数对于特性 error .
Returns true is audio decoding is supported on this platform.
Returns position (in milliseconds) of the last buffer read from the decoder or -1 if no buffers have been read.
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 () function before calling read() to make sure you get useful data.
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
() 会被设为
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 .
警告: Setting a desired audio format is not yet supported on Android.
另请参阅 audioFormat ().
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.
注意: setter 函数对于特性 source .
另请参阅 source ().
设置当前音频 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.
另请参阅 sourceDevice ().
Returns the current file name to decode. If setSourceDevice was called, this will be empty.
注意: getter 函数对于特性 source。
另请参阅 setSource ().
返回当前源 QIODevice , if one was set. If setSource () was called, this will be a nullptr.
另请参阅 setSourceDevice ().