CopperSpice API
1.9.1
|
Allows the playing of a media source. More...
Public Typedefs | |
using | Flags = QFlags< Flag > |
Public Types | |
enum | Error |
enum | Flag |
enum | MediaStatus |
enum | State |
Public Slots | |
void | pause () |
void | play () |
void | setMedia (const QMediaContent &media, QIODevice *stream=nullptr) |
void | setMuted (bool muted) |
void | setNetworkConfigurations (const QList< QNetworkConfiguration > &configurations) |
void | setPlaybackRate (qreal rate) |
void | setPlaylist (QMediaPlaylist *playlist) |
void | setPosition (qint64 position) |
void | setVolume (int volume) |
void | stop () |
Public Slots inherited from QObject | |
void | deleteLater () |
Public Methods | |
QMediaPlayer (QObject *parent=nullptr, Flags flags=Flags ()) | |
~QMediaPlayer () | |
QAudio::Role | audioRole () const |
QMultimedia::AvailabilityStatus | availability () const override |
int | bufferStatus () const |
QMediaContent | currentMedia () const |
QNetworkConfiguration | currentNetworkConfiguration () const |
qint64 | duration () const |
Error | error () const |
QString | errorString () const |
bool | isAudioAvailable () const |
bool | isMuted () const |
bool | isSeekable () const |
bool | isVideoAvailable () const |
QMediaContent | media () const |
MediaStatus | mediaStatus () const |
const QIODevice * | mediaStream () const |
qreal | playbackRate () const |
QMediaPlaylist * | playlist () const |
qint64 | position () const |
void | setAudioRole (QAudio::Role audioRole) |
void | setVideoOutput (QAbstractVideoSurface *surface) |
void | setVideoOutput (QGraphicsVideoItem *item) |
void | setVideoOutput (QVideoWidget *widget) |
State | state () const |
QList< QAudio::Role > | supportedAudioRoles () const |
int | volume () const |
Public Methods inherited from QMediaObject | |
~QMediaObject () | |
QStringList | availableMetaData () const |
virtual bool | bind (QObject *object) |
virtual bool | isAvailable () const |
bool | isMetaDataAvailable () const |
QVariant | metaData (const QString &key) const |
int | notifyInterval () const |
virtual QMediaService * | service () const |
void | setNotifyInterval (int milliSeconds) |
virtual void | unbind (QObject *object) |
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< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, 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 QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | 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) |
QThread * | thread () const |
Static Public Methods | |
static QMultimedia::SupportEstimate | hasSupport (const QString &mimeType, const QStringList &codecs=QStringList (), Flags flags=Flags ()) |
static QStringList | supportedMimeTypes (Flags flags=Flags ()) |
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 QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Properties | |
audioAvailable | |
Audio availability status for the current media. More... | |
audioRole | |
Audio stream played by the media player. More... | |
bufferStatus | |
Percentage of the temporary buffer filled before playback begins or resumes. More... | |
currentMedia | |
Current active media content being played by the player object. More... | |
duration | |
Duration of the current media. More... | |
error | |
String describing the last error condition. More... | |
media | |
Active media source used by the player object. More... | |
mediaStatus | |
Status of the current media stream. More... | |
muted | |
Muted state of the current media. More... | |
playbackRate | |
Playback rate of the current media. More... | |
playlist | |
Media playlist being used by the player object. More... | |
position | |
Playback position of the current media. More... | |
seekable | |
Seekable status of the current media. More... | |
state | |
Media player's current playback state. More... | |
videoAvailable | |
Video availability status for the current media. More... | |
volume | |
Current playback volume. 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) |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QMediaPlayer class is a high level media playback class. It can be used to playback such content as songs, movies and internet radio. The content to playback is specified as a QMediaContent object, which can be thought of as a main or canonical URL with additional information attached. When provided with a QMediaContent playback may be able to commence.
QVideoWidget can be used with QMediaPlayer for video rendering and QMediaPlaylist for accessing playlist functionality.
Since QMediaPlayer is a QMediaObject, you can use several of the QMediaObject functions for things like:
Typedef for QFlags<Flag> which contains an OR combination of Flag values.
Refer to QMediaPlayer::Flag for the enum documentation.
enum QMediaPlayer::Error |
Defines a media player error condition.
Constant | Value | Description |
---|---|---|
QMediaPlayer::NoError | 0 | No error has occurred. |
QMediaPlayer::ResourceError | 1 | Media resource could not be resolved |
QMediaPlayer::FormatError | 2 | Format of a media resource is not (fully) supported. Playback may still be possible, but without an audio or video component. |
QMediaPlayer::NetworkError | 3 | Network error occurred |
QMediaPlayer::AccessDeniedError | 4 | There are not the appropriate permissions to play a media resource. |
QMediaPlayer::ServiceMissingError | 5 | valid playback service was not found, playback cannot proceed |
enum QMediaPlayer::Flag |
Constant | Value | Description |
---|---|---|
QMediaPlayer::LowLatency | 0 | Player is expected to be used with simple audio formats, however playback should start without significant delay. Such playback service can be used for beeps, ringtones, etc. |
QMediaPlayer::StreamPlayback | 1 | Player is expected to play QIODevice based streams. If passed to QMediaPlayer constructor, the service supporting. streams playback will be chosen. |
QMediaPlayer::VideoSurface | 2 | Player is expected to be able to render to a QAbstractVideoSurface::setVideoOutput(). |
Defines the status of a media player's current media.
Constant | Value | Description |
---|---|---|
QMediaPlayer::UnknownMediaStatus | 0 | Status of the media can not be determined. |
QMediaPlayer::NoMedia | 1 | No current media, player is in the StoppedState. |
QMediaPlayer::LoadingMedia | 2 | Current media is being loaded, player may be in any state. |
QMediaPlayer::LoadedMedia | 3 | Current media has been loaded, player is in the StoppedState. |
QMediaPlayer::StalledMedia | 4 | Playback of the current media has stalled due to insufficient buffering or some other temporary interruption. Player is in the PlayingState or PausedState. |
QMediaPlayer::BufferingMedia | 5 | The player is buffering data but has enough data buffered for playback to continue for the immediate future. Player is in the PlayingState or PausedState. |
QMediaPlayer::BufferedMedia | 6 | Player has fully buffered the current media, player is in the PlayingState or PausedState. |
QMediaPlayer::EndOfMedia | 7 | Playback has reached the end of the current media,.player is in the StoppedState. |
QMediaPlayer::InvalidMedia | 8 | Current media can not be played, player is in the StoppedState. |
enum QMediaPlayer::State |
Defines the current state of a media player.
Constant | Value | Description |
---|---|---|
QMediaPlayer::StoppedState | 0 | Media player is not playing content, playback will begin from the start of the current track. |
QMediaPlayer::PlayingState | 1 | Media player is currently playing content. |
QMediaPlayer::PausedState | 2 | Media player has paused playback, playback of the current track will resume from the position here the player was paused. |
|
explicit |
Construct a QMediaPlayer instance parented to parent and with flags.
QMediaPlayer::~QMediaPlayer | ( | ) |
Destroys the player object.
|
signal |
Signals the availability of audio content has changed to available.
QAudio::Role QMediaPlayer::audioRole | ( | ) | const |
Returns the value of the property.
|
signal |
Signals the audio role of the media player has changed.
|
overridevirtual |
Returns the availability of the functionality offered by this object.
In some cases the functionality may not be available (for example, if the current operating system or platform does not provide the required functionality), or it may be temporarily unavailable (for example, audio playback during a phone call or similar).
Reimplemented from QMediaObject::availability()
int QMediaPlayer::bufferStatus | ( | ) | const |
Returns the value of the property.
|
signal |
Signal the amount of the local buffer filled as a percentage by percentFilled.
QMediaContent QMediaPlayer::currentMedia | ( | ) | const |
Returns the value of the property.
|
signal |
Signals the current playing content has been changed to content.
QNetworkConfiguration QMediaPlayer::currentNetworkConfiguration | ( | ) | const |
Returns the current network access point in use. If a default constructed QNetworkConfiguration is returned this feature is not available or that none of the current supplied configurations are in use.
qint64 QMediaPlayer::duration | ( | ) | const |
Returns the value of the property.
|
signal |
Signal the duration of the content has changed to duration, expressed in milliseconds.
QMediaPlayer::Error QMediaPlayer::error | ( | ) | const |
Returns the current error state.
|
signal |
Signals an error condition has occurred.
QString QMediaPlayer::errorString | ( | ) | const |
Returns the value of the error property.
|
static |
Returns the level of support a media player has for a mimeType and a set of codecs.
The flags argument allows additional requirements such as performance indicators to be specified.
bool QMediaPlayer::isAudioAvailable | ( | ) | const |
Returns the value of the audio availability status property.
bool QMediaPlayer::isMuted | ( | ) | const |
Returns the value of the muted property.
bool QMediaPlayer::isSeekable | ( | ) | const |
Returns the value of the seekable property.
bool QMediaPlayer::isVideoAvailable | ( | ) | const |
Returns the value of the video available property.
QMediaContent QMediaPlayer::media | ( | ) | const |
Returns the value of the property for the active media source used by the play object.
|
signal |
Signals the media source has been changed to media.
MediaStatus QMediaPlayer::mediaStatus | ( | ) | const |
Returns the value of the property indicating how the playback of the current stream is progressing.
|
signal |
Signals the status of the current media has changed.
const QIODevice * QMediaPlayer::mediaStream | ( | ) | const |
Returns the stream source of media data. This is only valid if a stream was passed to setMedia().
|
signal |
Signal the mute state has changed to muted.
|
signal |
Signal that the active in use network access point has been changed to configuration and all subsequent network access will use this configuration.
|
slot |
Pause playing the current source.
|
slot |
Start or resume playing the current source.
qreal QMediaPlayer::playbackRate | ( | ) | const |
Returns the value of the property.
|
signal |
Signals the playbackRate has changed to rate.
QMediaPlaylist * QMediaPlayer::playlist | ( | ) | const |
Returns the value of the property.
qint64 QMediaPlayer::position | ( | ) | const |
Returns the value of the property containing the playback position of the current media.
|
signal |
Signal the position of the content has changed to position, expressed in milliseconds.
|
signal |
Signals the seekable status of the player object has changed.
void QMediaPlayer::setAudioRole | ( | QAudio::Role | audioRole | ) |
Sets the value of the property to audioRole.
|
slot |
Sets the current media source.
If a stream is supplied, media data will be read from it instead of resolving the media source. In this case the media source may still be used to resolve additional information about the media such as mime type. The stream must be open and readable.
Setting the media to a null QMediaContent will cause the player to discard all information relating to the current media source and to cease all I/O operations related to that media.
|
slot |
Sets the value of the property to muted.
|
slot |
Sets the network access points for remote media playback. The configurations contains, in ascending preferential order, a list of configuration that can be used for network access.
This will invalidate the choice of previous configurations.
|
slot |
Sets the value of the property to rate.
|
slot |
Sets the value of the property to playlist.
|
slot |
Sets the value of the property to position.
void QMediaPlayer::setVideoOutput | ( | QAbstractVideoSurface * | surface | ) |
This method attaches a video surface to the media player. If the media player has an existing video output, it will be replaced.
void QMediaPlayer::setVideoOutput | ( | QGraphicsVideoItem * | item | ) |
This method attaches a video item to the media player. If the media player has an existing video output, it will be replaced.
void QMediaPlayer::setVideoOutput | ( | QVideoWidget * | widget | ) |
This method attaches a video widget to the media player. If the media player has an existing video output, it will be replaced.
|
slot |
Sets the value of the property to volume.
State QMediaPlayer::state | ( | ) | const |
Returns the value of the property.
|
signal |
Signal the state of the Player object has changed.
|
slot |
Stop playing, and reset the play position to the beginning.
QList< QAudio::Role > QMediaPlayer::supportedAudioRoles | ( | ) | const |
Returns a list of supported audio roles. If setting the audio role is not supported, an empty list is returned.
|
deprecatedstatic |
Returns a list of MIME types supported by the media player.
The flags argument causes the resultant list to be restricted to MIME types which can be supported given additional requirements, such as performance indicators.
This function may not return useful results on some platforms, and support for a specific file of a given mime type is not guaranteed even if the mime type is in general supported. In addition, in some cases this function will need to load all available media plugins and query them for their support, which may take some time.
|
signal |
Signal the availability of visual content has changed to videoAvailable.
int QMediaPlayer::volume | ( | ) | const |
Returns the value of the volume property.
|
signal |
Signal the playback volume has changed to volume.
|
This property stores the audio availability status for the current media.
As the life time of QMediaPlayer can be longer than the playback of one QMediaContent, this property may change over time, the audioAvailableChanged signal can be used to monitor it's status.
Properties | Class Methods |
---|---|
read | isAudioAvailable |
notify | audioAvailableChanged |
|
This property defines the role of the audio stream played by the media player.
This property can be set to specify the type of audio being played, allowing the system to make appropriate decisions when it comes to volume, routing or post-processing. The audio role must be set before calling setMedia().
Properties | Class Methods |
---|---|
read | audioRole |
write | setAudioRole |
|
This property defines the percentage of the temporary buffer filled before playback begins or resumes from 0 (empty) to 100 (full).
When the player object is buffering; this property holds the percentage of the temporary buffer that is filled. The buffer will need to reach 100% filled before playback can start or resume, at which time mediaStatus() will return BufferedMedia or BufferingMedia. If the value is anything lower than 100, mediaStatus() will return StalledMedia.
Properties | Class Methods |
---|---|
read | bufferStatus |
notify | bufferStatusChanged |
|
The property stores the current active media content being played by the player object.
This value could be different from QMediaPlayer::media property if a playlist is used. In this case currentMedia indicates the current media content being processed by the player, while QMediaPlayer::media property contains the original playlist.
Properties | Class Methods |
---|---|
read | currentMedia |
notify | currentMediaChanged |
|
This property stores the duration of the current media.
The value is the total playback time in milliseconds of the current media. The value may change across the life time of the QMediaPlayer object and may not be available when initial playback begins, connect to the durationChanged() signal to receive status notifications.
Properties | Class Methods |
---|---|
read | duration |
notify | durationChanged |
|
This property contains a string describing the last error condition.
Properties | Class Methods |
---|---|
read | errorString |
|
This property stores the active media source being used by the player object. The player object will use the QMediaContent for selection of the content to be played. By default this property has a null QMediaContent.
Setting this property to a null QMediaContent will cause the player to discard all information relating to the current media source and to cease all I/O operations related to that media.
Properties | Class Methods |
---|---|
read | media |
write | setMedia |
notify | mediaChanged |
|
This property stores the status of the current media stream. The stream status describes how the playback of the current stream is progressing. By default this property is QMediaPlayer::NoMedia.
Properties | Class Methods |
---|---|
read | mediaStatus |
notify | mediaStatusChanged |
|
This property stores the muted state of the current media. The value will be true if the playback volume is muted, otherwise false.
Properties | Class Methods |
---|---|
read | isMuted |
write | setMuted |
notify | mutedChanged |
|
This property defines the playback rate of the current media.
This value is a multiplier applied to the media's standard play rate. By default this value is 1.0, indicating that the media is playing at the standard pace. Values higher than 1.0 will increase the rate of play. Values less than zero can be set and indicate the media will rewind at the multiplier of the standard pace.
Not all playback services support change of the playback rate. The quality of audio and video while fast forwarding or rewinding depends on the platform media backend.
Properties | Class Methods |
---|---|
read | playbackRate |
write | setPlaybackRate |
notify | playbackRateChanged |
|
This property stores the media playlist being used by the player object. The player object will use the current playlist item for selection of the content to be played. By default this property is set to null.
If the media playlist is used as a source, QMediaPlayer::currentMedia is updated with a current playlist item. The current source should be selected with QMediaPlaylist::setCurrentIndex(int) instead of QMediaPlayer::setMedia(), otherwise the current playlist will be discarded.
Properties | Class Methods |
---|---|
read | playlist |
write | setPlaylist |
|
This property stores the playback position of the current media.
The value is the current playback position, expressed in milliseconds since the beginning of the media. Periodically changes in the position will be indicated with the signal positionChanged(), the interval between updates can be set with QMediaObject's method setNotifyInterval().
Properties | Class Methods |
---|---|
read | position |
write | setPosition |
notify | positionChanged |
|
This property stores the seekable status of the current media.
If seeking is supported this property will be true; false otherwise. The status of this property may change across the life time of the QMediaPlayer object, use the seekableChanged signal to monitor changes.
Properties | Class Methods |
---|---|
read | isSeekable |
notify | seekableChanged |
|
This property stores the media player's current playback state. By default this property is QMediaPlayer::Stopped
Properties | Class Methods |
---|---|
read | state |
notify | stateChanged |
|
This property stores the Video availability status for the current media.
If available, the QVideoWidget class can be used to view the video. As the life time of QMediaPlayer can be longer than the playback of one QMediaContent, this property may change over time, the videoAvailableChanged signal can be used to monitor it is status.
Properties | Class Methods |
---|---|
read | isVideoAvailable |
notify | videoAvailableChanged |
|
This property contains the current playback volume. The playback volume is linear in effect and the value can range from 0 - 100, values outside this range will be clamped.
Properties | Class Methods |
---|---|
read | volume |
write | setVolume |
notify | volumeChanged |