QMediaRecorder Class
The QMediaRecorder 检查媒体播放服务器是否可用. 更多...
头文件: | #include <QMediaRecorder> |
qmake: | QT += multimedia |
基类: | QObject and QMediaBindableInterface |
派生类: |
公有类型
enum | Error { NoError, ResourceError, FormatError, OutOfSpaceError } |
enum | State { StoppedState, RecordingState, PausedState } |
enum | Status { UnavailableStatus, UnloadedStatus, LoadingStatus, LoadedStatus, ..., FinalizingStatus } |
属性
|
|
- 1 个属性继承自 QObject
公有函数
QMediaRecorder(QMediaObject *mediaObject, QObject *parent = Q_NULLPTR) | |
~QMediaRecorder() | |
QUrl | actualLocation() const |
QString | audioCodecDescription(const QString &codec) const |
QAudioEncoderSettings | audioSettings() const |
QMultimedia::AvailabilityStatus | availability() const |
QStringList | availableMetaData() const |
QString | containerDescription(const QString &format) const |
QString | containerFormat() const |
qint64 | duration() const |
Error | error() const |
QString | errorString() const |
bool | isAvailable() const |
bool | isMetaDataAvailable() const |
bool | isMetaDataWritable() const |
bool | isMuted() const |
QVariant | metaData(const QString &key) const |
QUrl | outputLocation() const |
void | setAudioSettings(const QAudioEncoderSettings &settings) |
void | setContainerFormat(const QString &container) |
void | setEncodingSettings(const QAudioEncoderSettings &audio, const QVideoEncoderSettings &video = QVideoEncoderSettings(), const QString &container = QString()) |
void | setMetaData(const QString &key, const QVariant &value) |
bool | setOutputLocation(const QUrl &location) |
void | setVideoSettings(const QVideoEncoderSettings &settings) |
State | state() const |
Status | status() const |
QStringList | supportedAudioCodecs() const |
QList<int> | supportedAudioSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(), bool *continuous = Q_NULLPTR) const |
QStringList | supportedContainers() const |
QList<qreal> | supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), bool *continuous = Q_NULLPTR) const |
QList<QSize> | supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), bool *continuous = Q_NULLPTR) const |
QStringList | supportedVideoCodecs() const |
QString | videoCodecDescription(const QString &codec) const |
QVideoEncoderSettings | videoSettings() const |
qreal | volume() const |
重新实现的公有函数
virtual QMediaObject * | mediaObject() const override |
- 32 个公有函数继承自 QObject
- 1 个公有函数继承自 QMediaBindableInterface
公有槽函数
- 1 个公有槽函数继承自 QObject
信号
void | actualLocationChanged(const QUrl &location) |
void | availabilityChanged(bool available) |
void | availabilityChanged(QMultimedia::AvailabilityStatus availability) |
void | durationChanged(qint64 duration) |
void | error(QMediaRecorder::Error error) |
void | metaDataAvailableChanged(bool available) |
void | metaDataChanged() |
void | metaDataChanged(const QString &key, const QVariant &value) |
void | metaDataWritableChanged(bool writable) |
void | mutedChanged(bool muted) |
void | stateChanged(QMediaRecorder::State state) |
void | statusChanged(QMediaRecorder::Status status) |
void | volumeChanged(qreal volume) |
- 2 个信号继承自 QObject
其他继承的成员
- 1 个公有变量继承自 QObject
- 10 个静态公有成员继承自 QObject
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QMediaBindableInterface
- 2 个受保护的变量继承自 QObject
详细描述
QMediaRecorder 是一个高级多媒体记录类. 它不单独使用, 而是配合其他多媒体类提供录制功能, 如 QRadioTuner, QCamera.
recorder = new QMediaRecorder(camera); QAudioEncoderSettings audioSettings; audioSettings.setCodec("audio/amr"); audioSettings.setQuality(QMultimedia::HighQuality); recorder->setAudioSettings(audioSettings); recorder->setOutputLocation(QUrl::fromLocalFile(fileName)); recorder->record();
参见 QAudioRecorder.
成员类型
enum QMediaRecorder::Error
Constant | Value | Description |
---|---|---|
QMediaRecorder::NoError | 0 | No Errors. |
QMediaRecorder::ResourceError | 1 | Device is not ready or not available. |
QMediaRecorder::FormatError | 2 | Current format is not supported. |
QMediaRecorder::OutOfSpaceError | 3 | No space left on device. |
enum QMediaRecorder::State
Constant | Value | Description |
---|---|---|
QMediaRecorder::StoppedState | 0 | The recorder is not active. |
QMediaRecorder::RecordingState | 1 | The recording is requested. |
QMediaRecorder::PausedState | 2 | The recorder is paused. |
enum QMediaRecorder::Status
Constant | Value | Description |
---|---|---|
QMediaRecorder::UnavailableStatus | 0 | The recorder is not available or not supported by connected media object. |
QMediaRecorder::UnloadedStatus | 1 | The recorder is avilable but not loaded. |
QMediaRecorder::LoadingStatus | 2 | The recorder is initializing. |
QMediaRecorder::LoadedStatus | 3 | The recorder is initialized and ready to record media. |
QMediaRecorder::StartingStatus | 4 | Recording is requested but not active yet. |
QMediaRecorder::RecordingStatus | 5 | Recording is active. |
QMediaRecorder::PausedStatus | 6 | Recording is paused. |
QMediaRecorder::FinalizingStatus | 7 | Recording is stopped with media being finalized. |
属性
actualLocation : const QUrl
This property holds the actual location of the last media content.
The actual location is usually available after recording starts, and reset when new location is set or new recording starts.
访问函数:
QUrl | actualLocation() const |
Notifier signal:
void | actualLocationChanged(const QUrl &location) |
duration : const qint64
This property holds the recorded media duration in milliseconds.
访问函数:
qint64 | duration() const |
Notifier signal:
void | durationChanged(qint64 duration) |
metaDataAvailable : const bool
This property holds whether access to a media object's meta-data is available.
If this is true there is meta-data available, otherwise there is no meta-data available.
访问函数:
bool | isMetaDataAvailable() const |
Notifier signal:
void | metaDataAvailableChanged(bool available) |
metaDataWritable : const bool
This property holds whether a media object's meta-data is writable.
If this is true the meta-data is writable, otherwise the meta-data is read-only.
访问函数:
bool | isMetaDataWritable() const |
Notifier signal:
void | metaDataWritableChanged(bool writable) |
muted : bool
This property holds whether a recording audio stream is muted.
访问函数:
bool | isMuted() const |
void | setMuted(bool muted) |
Notifier signal:
void | mutedChanged(bool muted) |
outputLocation : QUrl
This property holds the destination location of media content.
Setting the location can fail, for example when the service supports only local file system locations but a network URL was passed. If the service does not support media recording this setting the output location will always fail.
The location can be relative or empty; in this case the recorder uses the system specific place and file naming scheme. After recording has stated, QMediaRecorder::outputLocation() returns the actual output location.
访问函数:
QUrl | outputLocation() const |
bool | setOutputLocation(const QUrl &location) |
state : const QMediaRecorder::State
This property holds the current state of the media recorder.
The state property represents the user request and is changed synchronously during record(), pause() or stop() calls. Recorder state may also change asynchronously when recording fails.
访问函数:
State | state() const |
Notifier signal:
void | stateChanged(QMediaRecorder::State state) |
status : const QMediaRecorder::Status
This property holds the current status of the media recorder.
The status is changed asynchronously and represents the actual status of media recorder.
访问函数:
Status | status() const |
Notifier signal:
void | statusChanged(QMediaRecorder::Status status) |
volume : qreal
This property holds the current recording audio volume.
The volume is scaled linearly from 0.0
(silence) to 1.0
(full volume). Values outside this range will be clamped.
The default volume is 1.0
.
UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale will produce linear changes in perceived loudness, which is what a user would normally expect from a volume control. See QAudio::convertVolume() for more details.
访问函数:
qreal | volume() const |
void | setVolume(qreal volume) |
Notifier signal:
void | volumeChanged(qreal volume) |
成员函数
QMediaRecorder::QMediaRecorder(QMediaObject *mediaObject, QObject *parent = Q_NULLPTR)
Constructs a media recorder which records the media produced by mediaObject.
The parent is passed to QMediaObject.
QMediaRecorder::~QMediaRecorder()
Destroys a media recorder object.
[signal]
void QMediaRecorder::actualLocationChanged(const QUrl &location)
Signals that the actual location of the recorded media has changed. This signal is usually emitted when recording starts.
Note: Notifier signal for property actualLocation.
QString QMediaRecorder::audioCodecDescription(const QString &codec) const
Returns a description of an audio codec.
QAudioEncoderSettings QMediaRecorder::audioSettings() const
Returns the audio encoder settings being used.
参见 setAudioSettings() and setEncodingSettings().
QMultimedia::AvailabilityStatus QMediaRecorder::availability() const
Returns the availability of this functionality.
参见 availabilityChanged().
[signal]
void QMediaRecorder::availabilityChanged(bool available)
Signals that the media recorder is now available (if available is true), or not.
Note: Signal availabilityChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(mediaRecorder, static_cast<void(QMediaRecorder::*)(bool)>(&QMediaRecorder::availabilityChanged), [=](bool available){ /* ... */ });
[signal]
void QMediaRecorder::availabilityChanged(QMultimedia::AvailabilityStatus availability)
Signals that the service availability has changed to availability.
Note: Signal availabilityChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(mediaRecorder, static_cast<void(QMediaRecorder::*)(QMultimedia::AvailabilityStatus)>(&QMediaRecorder::availabilityChanged), [=](QMultimedia::AvailabilityStatus availability){ /* ... */ });
QStringList QMediaRecorder::availableMetaData() const
Returns a list of keys there is meta-data available for.
QString QMediaRecorder::containerDescription(const QString &format) const
Returns a description of a container format.
QString QMediaRecorder::containerFormat() const
Returns the selected container format.
参见 setContainerFormat().
[signal]
void QMediaRecorder::durationChanged(qint64 duration)
Signals that the duration of the recorded media has changed.
Note: Notifier signal for property duration.
Error QMediaRecorder::error() const
Returns the current error state.
参见 errorString().
[signal]
void QMediaRecorder::error(QMediaRecorder::Error error)
Signals that an error has occurred.
Note: Signal error is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(mediaRecorder, static_cast<void(QMediaRecorder::*)(QMediaRecorder::Error)>(&QMediaRecorder::error), [=](QMediaRecorder::Error error){ /* ... */ });
QString QMediaRecorder::errorString() const
Returns a string describing the current error state.
参见 error().
bool QMediaRecorder::isAvailable() const
Returns true if media recorder service ready to use.
参见 availabilityChanged().
[override virtual]
QMediaObject *QMediaRecorder::mediaObject() const
Reimplemented from QMediaBindableInterface::mediaObject().
Returns the QMediaObject instance that this QMediaRecorder is bound too, or 0 otherwise.
QVariant QMediaRecorder::metaData(const QString &key) const
Returns the value associated with a meta-data key.
参见 setMetaData().
[signal]
void QMediaRecorder::metaDataAvailableChanged(bool available)
Signals that the available state of a media object's meta-data has changed.
Note: Notifier signal for property metaDataAvailable.
[signal]
void QMediaRecorder::metaDataChanged()
Signals that a media object's meta-data has changed.
If multiple meta-data elements are changed, metaDataChanged(const QString &key, const QVariant &value) signal is emitted for each of them with metaDataChanged() changed emitted once.
Note: Signal metaDataChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(mediaRecorder, static_cast<void(QMediaRecorder::*)()>(&QMediaRecorder::metaDataChanged), [=](){ /* ... */ });
[signal]
void QMediaRecorder::metaDataChanged(const QString &key, const QVariant &value)
Signal the changes of one meta-data element value with the given key.
Note: Signal metaDataChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(mediaRecorder, static_cast<void(QMediaRecorder::*)(const QString &, const QVariant &)>(&QMediaRecorder::metaDataChanged), [=](const QString &key, const QVariant &value){ /* ... */ });
[signal]
void QMediaRecorder::metaDataWritableChanged(bool writable)
Signals that the writable state of a media object's meta-data has changed.
Note: Notifier signal for property metaDataWritable.
[signal]
void QMediaRecorder::mutedChanged(bool muted)
Signals that the muted state has changed. If true the recording is being muted.
Note: Notifier signal for property muted.
[slot]
void QMediaRecorder::pause()
Pause recording.
The recorder state is changed to QMediaRecorder::PausedState.
Depending on platform recording pause may be not supported, in this case the recorder state stays unchanged.
[slot]
void QMediaRecorder::record()
Start recording.
While the recorder state is changed immediately to QMediaRecorder::RecordingState, recording may start asynchronously, with statusChanged(QMediaRecorder::RecordingStatus) signal emitted when recording starts.
If recording fails error() signal is emitted with recorder state being reset back to QMediaRecorder::StoppedState.
void QMediaRecorder::setAudioSettings(const QAudioEncoderSettings &settings)
Sets the audio encoder settings.
If some parameters are not specified, or null settings are passed, the encoder will choose default encoding parameters, depending on media source properties.
It's only possible to change settings when the encoder is in the QMediaEncoder::StoppedState state.
参见 audioSettings(), videoSettings(), and containerFormat().
void QMediaRecorder::setContainerFormat(const QString &container)
Sets the media container format.
If the container format is not specified, the encoder will choose format, depending on media source properties and encoding settings selected.
It's only possible to change settings when the encoder is in the QMediaEncoder::StoppedState state.
参见 audioSettings(), videoSettings(), and containerFormat().
void QMediaRecorder::setEncodingSettings(const QAudioEncoderSettings &audio, const QVideoEncoderSettings &video = QVideoEncoderSettings(), const QString &container = QString())
Sets the audio and video encoder settings and container format.
If some parameters are not specified, or null settings are passed, the encoder will choose default encoding parameters, depending on media source properties.
It's only possible to change settings when the encoder is in the QMediaEncoder::StoppedState state.
参见 audioSettings(), videoSettings(), and containerFormat().
void QMediaRecorder::setMetaData(const QString &key, const QVariant &value)
Sets a value for a meta-data key.
Note: To ensure that meta data is set corretly, it should be set before starting the recording. Once the recording is stopped, any meta data set will be attached to the next recording.
参见 metaData().
void QMediaRecorder::setVideoSettings(const QVideoEncoderSettings &settings)
Sets the video encoder settings.
If some parameters are not specified, or null settings are passed, the encoder will choose default encoding parameters, depending on media source properties.
It's only possible to change settings when the encoder is in the QMediaEncoder::StoppedState state.
参见 audioSettings(), videoSettings(), and containerFormat().
State QMediaRecorder::state() const
Returns the current media recorder state.
Note: Getter function for property state.
[signal]
void QMediaRecorder::stateChanged(QMediaRecorder::State state)
Signals that a media recorder's state has changed.
Note: Notifier signal for property state.
Status QMediaRecorder::status() const
Returns the current media recorder status.
Note: Getter function for property status.
[slot]
void QMediaRecorder::stop()
Stop recording.
The recorder state is changed to QMediaRecorder::StoppedState.
QStringList QMediaRecorder::supportedAudioCodecs() const
Returns a list of supported audio codecs.
QList<int> QMediaRecorder::supportedAudioSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(), bool *continuous = Q_NULLPTR) const
Returns a list of supported audio sample rates.
If non null audio settings parameter is passed, the returned list is reduced to sample rates supported with partial settings applied.
This can be used to query the list of sample rates, supported by specific audio codec.
If the encoder supports arbitrary sample rates within the supported rates range, *continuous is set to true, otherwise *continuous is set to false.
QStringList QMediaRecorder::supportedContainers() const
Returns a list of supported container formats.
QList<qreal> QMediaRecorder::supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), bool *continuous = Q_NULLPTR) const
Returns a list of frame rates video can be encoded at.
If non null video settings parameter is passed, the returned list is reduced to frame rates supported with partial settings like video codec or resolution applied.
If the encoder supports arbitrary frame rates within the supported range, *continuous is set to true, otherwise *continuous is set to false.
参见 QVideoEncoderSettings::frameRate().
QList<QSize> QMediaRecorder::supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), bool *continuous = Q_NULLPTR) const
Returns a list of resolutions video can be encoded at.
If non null video settings parameter is passed, the returned list is reduced to resolution supported with partial settings like video codec or framerate applied.
If the encoder supports arbitrary resolutions within the supported range, *continuous is set to true, otherwise *continuous is set to false.
参见 QVideoEncoderSettings::resolution().
QStringList QMediaRecorder::supportedVideoCodecs() const
Returns a list of supported video codecs.
QString QMediaRecorder::videoCodecDescription(const QString &codec) const
Returns a description of a video codec.
参见 setEncodingSettings().
QVideoEncoderSettings QMediaRecorder::videoSettings() const
Returns the video encoder settings being used.
参见 setVideoSettings() and setEncodingSettings().