Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QMediaPlayer Class Reference

The QMediaPlayer class allows the playing of a media files. More...

#include <qmediaplayer.h>

Inheritance diagram for QMediaPlayer:
Collaboration diagram for QMediaPlayer:

Public Types

enum  PlaybackState { StoppedState , PlayingState , PausedState }
 Defines the current state of a media player. More...
enum  MediaStatus {
  NoMedia , LoadingMedia , LoadedMedia , StalledMedia ,
  BufferingMedia , BufferedMedia , EndOfMedia , InvalidMedia
}
 \qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState More...
enum  Error {
  NoError , ResourceError , FormatError , NetworkError ,
  AccessDeniedError
}
 \qmlproperty enumeration QtMultimedia::MediaPlayer::mediaStatus More...
enum  Loops { Infinite = -1 , Once = 1 }
 Some predefined constants for the \l loops property. More...
enum class  PitchCompensationAvailability { AlwaysOn , Available , Unavailable }

Public Slots

void play ()
 \qmlmethod QtMultimedia::MediaPlayer::play()
void pause ()
 \qmlmethod QtMultimedia::MediaPlayer::pause()
void stop ()
 \qmlmethod QtMultimedia::MediaPlayer::stop()
void setPosition (qint64 position)
void setPlaybackRate (qreal rate)
void setSource (const QUrl &source)
 \qmlproperty url QtMultimedia::MediaPlayer::source
void setSourceDevice (QIODevice *device, const QUrl &sourceUrl=QUrl())
 Sets the current source device.
void setPitchCompensation (bool) const
 Sets the state (enabled or disabled) of pitch compensation.
void setPlaybackOptions (const QPlaybackOptions &options)
void resetPlaybackOptions ()
Public Slots inherited from QObject
void deleteLater ()
 \threadsafe

Signals

void sourceChanged (const QUrl &media)
 Signals that the media source has been changed to media.
void playbackStateChanged (QMediaPlayer::PlaybackState newState)
void mediaStatusChanged (QMediaPlayer::MediaStatus status)
 Signals that the status of the current media has changed.
void durationChanged (qint64 duration)
 Signals the duration of the content has changed to duration, expressed in milliseconds.
void positionChanged (qint64 position)
 Signals the position of the content has changed to position, expressed in milliseconds.
void hasAudioChanged (bool available)
 Signals the availability of audio content has changed to available.
void hasVideoChanged (bool videoAvailable)
 Signals the availability of visual content has changed to videoAvailable.
void bufferProgressChanged (float progress)
 Signals the amount of the local buffer filled as a number between 0 and 1.
void seekableChanged (bool seekable)
 Signals the seekable status of the player object has changed.
void playingChanged (bool playing)
void playbackRateChanged (qreal rate)
 Signals the playbackRate has changed to rate.
void loopsChanged ()
void metaDataChanged ()
void videoOutputChanged ()
void audioOutputChanged ()
 Q_REVISION (6, 8) void audioBufferOutputChanged()
void tracksChanged ()
void activeTracksChanged ()
void errorChanged ()
void errorOccurred (QMediaPlayer::Error error, const QString &errorString)
 \qmlsignal QtMultimedia::MediaPlayer::errorOccurred(error, errorString)
void pitchCompensationChanged (bool)
void playbackOptionsChanged ()
Signals inherited from QObject
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

 QMediaPlayer (QObject *parent=nullptr)
 Constructs a QMediaPlayer instance as a child of {parent}.
 ~QMediaPlayer () override
 Destroys the player object.
QList< QMediaMetaDataaudioTracks () const
QList< QMediaMetaDatavideoTracks () const
QList< QMediaMetaDatasubtitleTracks () const
int activeAudioTrack () const
int activeVideoTrack () const
int activeSubtitleTrack () const
void setActiveAudioTrack (int index)
void setActiveVideoTrack (int index)
void setActiveSubtitleTrack (int index)
void setAudioBufferOutput (QAudioBufferOutput *output)
QAudioBufferOutputaudioBufferOutput () const
void setAudioOutput (QAudioOutput *output)
QAudioOutputaudioOutput () const
void setVideoOutput (QObject *)
QObjectvideoOutput () const
void setVideoSink (QVideoSink *sink)
 Sets sink to be the QVideoSink instance to retrieve video data.
QVideoSinkvideoSink () const
 Returns the QVideoSink instance.
QUrl source () const
const QIODevicesourceDevice () const
 Returns the stream source of media data.
PlaybackState playbackState () const
MediaStatus mediaStatus () const
qint64 duration () const
 Returns the duration of the current media in ms.
qint64 position () const
 Returns the current position inside the media being played back in ms.
bool hasAudio () const
bool hasVideo () const
float bufferProgress () const
 Returns a number between 0 and 1 when buffering data.
QMediaTimeRange bufferedTimeRange () const
 Returns a QMediaTimeRange describing the currently buffered data.
bool isSeekable () const
 Returns true if the media is seekable.
qreal playbackRate () const
 Returns the current playback rate.
bool isPlaying () const
int loops () const
 \qmlproperty int QtMultimedia::MediaPlayer::loops
void setLoops (int loops)
Error error () const
 Returns the current error state.
QString errorString () const
bool isAvailable () const
 Returns true if the media player is supported on this platform.
QMediaMetaData metaData () const
PitchCompensationAvailability pitchCompensationAvailability () const
 \qmlproperty enumeration QtMultimedia::MediaPlayer::pitchCompensationAvailability
bool pitchCompensation () const
 Returns the state of pitch compensation.
QPlaybackOptions playbackOptions () const
Public Member Functions inherited from QObject
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< QStringbindableObjectName ()
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 isQmlObjectType () const
 Returns whether the object has been created by the QML engine or ownership has been explicitly set via QJSEngine::setObjectOwnership().
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).
QThreadthread () const
 Returns the thread in which the object lives.
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
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::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
void killTimer (int id)
 Kills the timer with timer identifier, id.
void killTimer (Qt::TimerId id)
template<typename T>
findChild (QAnyStringView aName, 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 (QAnyStringView 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>
findChild (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.
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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () const
QBindingStoragebindingStorage ()
const QBindingStoragebindingStorage () const
QObjectparent () 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 media source being used by the player object.
qint64 duration
 \qmlproperty int QtMultimedia::MediaPlayer::duration
qint64 position
 \qmlproperty int QtMultimedia::MediaPlayer::position
float bufferProgress
 \qmlproperty real QtMultimedia::MediaPlayer::bufferProgress
bool hasAudio
 \qmlproperty bool QtMultimedia::MediaPlayer::hasAudio
bool hasVideo
 \qmlproperty bool QtMultimedia::MediaPlayer::hasVideo
bool seekable
 \qmlproperty bool QtMultimedia::MediaPlayer::seekable
bool playing
 \qmlproperty bool QtMultimedia::MediaPlayer::playing
qreal playbackRate
 \qmlproperty real QtMultimedia::MediaPlayer::playbackRate
int loops
 Determines how often the media is played before the player stops.
PlaybackState playbackState
 Returns the \l{QMediaPlayer::}{PlaybackState}.
MediaStatus mediaStatus
 the status of the current media stream.
QMediaMetaData metaData
 \qmlproperty mediaMetaData QtMultimedia::MediaPlayer::metaData
Error error
 a string describing the last error condition.
QString errorString
 \qmlproperty string QtMultimedia::MediaPlayer::errorString
QObjectvideoOutput
 \qmlproperty VideoOutput QtMultimedia::MediaPlayer::videoOutput
QAudioOutputaudioOutput
 \qmlproperty AudioOutput QtMultimedia::MediaPlayer::audioOutput
QAudioBufferOutputaudioBufferOutput
 \qmlproperty QAudioBufferOutput QtMultimedia::MediaPlayer::audioBufferOutput
QList< QMediaMetaDataaudioTracks
 \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::audioTracks
QList< QMediaMetaDatavideoTracks
 \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::videoTracks
QList< QMediaMetaDatasubtitleTracks
 \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::subtitleTracks
int activeAudioTrack
 \qmlproperty int QtMultimedia::MediaPlayer::activeAudioTrack
int activeVideoTrack
 Returns the currently active video track.
int activeSubtitleTrack
 Returns the currently active subtitle track.
PitchCompensationAvailability pitchCompensationAvailability READ pitchCompensationAvailability CONSTANT Q_PROPERTYbool pitchCompensation
 \qmlproperty bool QtMultimedia::MediaPlayer::pitchCompensation
QPlaybackOptions playbackOptions
 \qmlproperty playbackOptions MediaPlayer::playbackOptions
Properties inherited from QObject
QString objectName
 the name of this object

Friends

class QPlatformMediaPlayer

Additional Inherited Members

Static Public Member Functions inherited from QObject
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)
Protected Member Functions inherited from QObject
QObjectsender () 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)
Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr

Detailed Description

The QMediaPlayer class allows the playing of a media files.

\inmodule QtMultimedia

The QMediaPlayer class is a high level media playback class. It can be used to playback audio of video media files. The content to playback is specified as a QUrl object.

QVideoWidget can be used with QMediaPlayer for video rendering.

See also
QVideoWidget

Definition at line 23 of file qmediaplayer.h.

Member Enumeration Documentation

◆ Error

\qmlproperty enumeration QtMultimedia::MediaPlayer::mediaStatus

This property holds the status of media loading. It can be one of the following:

\table \header

  • Property value
  • Description \row
  • NoMedia
  • No media has been set. \row
  • LoadingMedia
  • The media is currently being loaded. \row
  • LoadedMedia
  • The media has been loaded. \row
  • BufferingMedia
  • The media is buffering data. \row
  • StalledMedia
  • Playback has been interrupted while the media is buffering data. \row
  • BufferedMedia
  • The media has buffered data. \row
  • EndOfMedia
  • The media has played to the end. \row
  • InvalidMedia
  • The media cannot be played. \endtable

\qmlproperty enumeration QtMultimedia::MediaPlayer::error

This property holds the error state of the audio. It can be one of the following.

\table \header

  • Value
  • Description \row
  • NoError
  • There is no current error. \row
  • ResourceError
  • The audio cannot be played due to a problem allocating resources. \row
  • FormatError
  • The audio format is not supported. \row
  • NetworkError
  • The audio cannot be played due to network issues. \row
  • AccessDeniedError
  • The audio cannot be played due to insufficient permissions. \endtable

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 (fully) supported. Playback may still be possible, but without an audio or video component. \value NetworkError A network error occurred. \value AccessDeniedError There are not the appropriate permissions to play a media resource.

Enumerator
NoError 
ResourceError 
FormatError 
NetworkError 
AccessDeniedError 

Definition at line 92 of file qmediaplayer.h.

◆ Loops

Some predefined constants for the \l loops property.

\value Infinite Loop forever. \value Once Play the media once (the default).

Enumerator
Infinite 
Once 

Definition at line 102 of file qmediaplayer.h.

◆ MediaStatus

\qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState

This property holds the state of media playback. It can be one of the following:

\table \header

  • Property value
  • Description \row
  • PlayingState
  • The media is currently playing. This indicates the same as the \l playing property. \row
  • PausedState
  • Playback of the media has been suspended. \row
  • StoppedState
  • Playback of the media is yet to begin. \endtable

\qmlsignal QtMultimedia::MediaPlayer::playbackStateChanged()

This signal is emitted when the \l playbackState property is altered.

\qmlsignal QtMultimedia::MediaPlayer::playingChanged()

This signal is emitted when the \l playing property changes.

Defines the status of a media player's current media.

\value NoMedia The is no current media. The player is in the StoppedState. \value LoadingMedia The current media is being loaded. The player may be in any state. \value LoadedMedia The current media has been loaded. The player is in the StoppedState. \value StalledMedia Playback of the current media has stalled due to insufficient buffering or some other temporary interruption. The player is in the PlayingState or PausedState. \value BufferingMedia The player is buffering data but has enough data buffered for playback to continue for the immediate future. The player is in the PlayingState or PausedState. \value BufferedMedia The player has fully buffered the current media. The player is in the PlayingState or PausedState. \value EndOfMedia Playback has reached the end of the current media. The player is in the StoppedState. \value InvalidMedia The current media cannot be played. The player is in the StoppedState.

Enumerator
NoMedia 
LoadingMedia 
LoadedMedia 
StalledMedia 
BufferingMedia 
BufferedMedia 
EndOfMedia 
InvalidMedia 

Definition at line 79 of file qmediaplayer.h.

◆ PitchCompensationAvailability

Since
6.10

Availablility of pitch compensation.

Different backends have different behavior regarding pitch compensation when changing playback rate.

\value AlwaysOn The media player is always performing pitch compensation. \value Available The media player can be configured to use pitch compensation. If pitch compensation is available on the current platform, it will be enabled by default, but users can disable if needed. \value Unavailable The media player is not able to perform pitch compensation on the current platform.

Enumerator
AlwaysOn 
Available 
Unavailable 

Definition at line 109 of file qmediaplayer.h.

◆ PlaybackState

Defines the current state of a media player.

\value StoppedState The media player is not playing content, playback will begin from the start of the current track. \value PlayingState The media player is currently playing content. This indicates the same as the \l playing property. \value PausedState The media player has paused playback, playback of the current track will resume from the position the player was paused at.

Enumerator
StoppedState 
PlayingState 
PausedState 

Definition at line 71 of file qmediaplayer.h.

Constructor & Destructor Documentation

◆ QMediaPlayer()

QMediaPlayer::QMediaPlayer ( QObject * parent = nullptr)
explicit

Constructs a QMediaPlayer instance as a child of {parent}.

Definition at line 247 of file qmediaplayer.cpp.

◆ ~QMediaPlayer()

QMediaPlayer::~QMediaPlayer ( )
override

Destroys the player object.

Definition at line 267 of file qmediaplayer.cpp.

Member Function Documentation

◆ activeAudioTrack()

int QMediaPlayer::activeAudioTrack ( ) const

Definition at line 898 of file qmediaplayer.cpp.

◆ activeSubtitleTrack()

int QMediaPlayer::activeSubtitleTrack ( ) const

Definition at line 946 of file qmediaplayer.cpp.

◆ activeTracksChanged

void QMediaPlayer::activeTracksChanged ( )
signal

◆ activeVideoTrack()

int QMediaPlayer::activeVideoTrack ( ) const

Definition at line 922 of file qmediaplayer.cpp.

◆ audioBufferOutput()

QAudioBufferOutput * QMediaPlayer::audioBufferOutput ( ) const

Definition at line 750 of file qmediaplayer.cpp.

◆ audioOutput()

QAudioOutput * QMediaPlayer::audioOutput ( ) const

Definition at line 794 of file qmediaplayer.cpp.

◆ audioOutputChanged

void QMediaPlayer::audioOutputChanged ( )
signal

◆ audioTracks()

QList< QMediaMetaData > QMediaPlayer::audioTracks ( ) const

Definition at line 823 of file qmediaplayer.cpp.

◆ bufferedTimeRange()

QMediaTimeRange QMediaPlayer::bufferedTimeRange ( ) const

Returns a QMediaTimeRange describing the currently buffered data.

When streaming media from a remote source, different parts of the media file can be available locally. The returned QMediaTimeRange object describes the time ranges that are buffered and available for immediate playback.

See also
QMediaTimeRange

Definition at line 387 of file qmediaplayer.cpp.

◆ bufferProgress()

float QMediaPlayer::bufferProgress ( ) const

Returns a number between 0 and 1 when buffering data.

0 means that there is no buffered data available, playback is usually stalled in this case. Playback will resume once the buffer reaches 1, meaning enough data has been buffered to be able to resume playback.

bufferProgress() will always return 1 for local files.

Definition at line 372 of file qmediaplayer.cpp.

◆ bufferProgressChanged

void QMediaPlayer::bufferProgressChanged ( float progress)
signal

Signals the amount of the local buffer filled as a number between 0 and 1.

◆ duration()

qint64 QMediaPlayer::duration ( ) const

Returns the duration of the current media in ms.

Returns 0 if the media player doesn't have a valid media file or stream. For live streams, the duration usually changes during playback as more data becomes available.

Definition at line 344 of file qmediaplayer.cpp.

◆ durationChanged

void QMediaPlayer::durationChanged ( qint64 duration)
signal

Signals the duration of the content has changed to duration, expressed in milliseconds.

◆ error()

QMediaPlayer::Error QMediaPlayer::error ( ) const

Returns the current error state.

Definition at line 496 of file qmediaplayer.cpp.

◆ errorChanged

void QMediaPlayer::errorChanged ( )
signal

◆ errorOccurred

void QMediaPlayer::errorOccurred ( QMediaPlayer::Error error,
const QString & errorString )
signal

\qmlsignal QtMultimedia::MediaPlayer::errorOccurred(error, errorString)

This signal is emitted when an error has occurred. The errorString parameter may contain more detailed information about the error.

See also
QMediaPlayer::Error

Signals that an error condition has occurred, with errorString containing a description of the error.

See also
errorString()

◆ errorString()

QString QMediaPlayer::errorString ( ) const

Definition at line 513 of file qmediaplayer.cpp.

◆ hasAudio()

bool QMediaPlayer::hasAudio ( ) const

Definition at line 403 of file qmediaplayer.cpp.

◆ hasAudioChanged

void QMediaPlayer::hasAudioChanged ( bool available)
signal

Signals the availability of audio content has changed to available.

◆ hasVideo()

bool QMediaPlayer::hasVideo ( ) const

Definition at line 419 of file qmediaplayer.cpp.

◆ hasVideoChanged

void QMediaPlayer::hasVideoChanged ( bool videoAvailable)
signal

Signals the availability of visual content has changed to videoAvailable.

◆ isAvailable()

bool QMediaPlayer::isAvailable ( ) const

Returns true if the media player is supported on this platform.

Definition at line 1066 of file qmediaplayer.cpp.

◆ isPlaying()

bool QMediaPlayer::isPlaying ( ) const

Definition at line 437 of file qmediaplayer.cpp.

◆ isSeekable()

bool QMediaPlayer::isSeekable ( ) const

Returns true if the media is seekable.

Most file based media files are seekable, but live streams usually are not.

See also
position

Definition at line 431 of file qmediaplayer.cpp.

◆ loops()

int QMediaPlayer::loops ( ) const

\qmlproperty int QtMultimedia::MediaPlayer::loops

Determines how often the media is played before the player stops. Set to MediaPlayer::Infinite to loop the current media file forever.

The default value is 1. Setting this property to 0 has no effect.

Definition at line 478 of file qmediaplayer.cpp.

◆ loopsChanged

void QMediaPlayer::loopsChanged ( )
signal

◆ mediaStatus()

QMediaPlayer::MediaStatus QMediaPlayer::mediaStatus ( ) const

Definition at line 331 of file qmediaplayer.cpp.

◆ mediaStatusChanged

void QMediaPlayer::mediaStatusChanged ( QMediaPlayer::MediaStatus status)
signal

Signals that the status of the current media has changed.

See also
mediaStatus()

◆ metaData()

QMediaMetaData QMediaPlayer::metaData ( ) const

Definition at line 1093 of file qmediaplayer.cpp.

◆ metaDataChanged

void QMediaPlayer::metaDataChanged ( )
signal

◆ pause

void QMediaPlayer::pause ( )
slot

\qmlmethod QtMultimedia::MediaPlayer::pause()

Pauses playback of the media.

Sets the \l playbackState property to PausedState, and changes \l playing to false.

Pause playing the current source.

See also
play(), stop()

Definition at line 556 of file qmediaplayer.cpp.

◆ pitchCompensation()

bool QMediaPlayer::pitchCompensation ( ) const

Returns the state of pitch compensation.

Since
6.10

Definition at line 1123 of file qmediaplayer.cpp.

◆ pitchCompensationAvailability()

QMediaPlayer::PitchCompensationAvailability QMediaPlayer::pitchCompensationAvailability ( ) const

\qmlproperty enumeration QtMultimedia::MediaPlayer::pitchCompensationAvailability

Returns availability of pitch compensation of the current backend.

Since
6.10

Indicates the availability of pitch compensation of the MediaPlayer on the current backend. The enumeration PitchCompensationAvailability is scoped.

\qmlenumeratorsfrom QMediaPlayer::PitchCompensationAvailability

The pitch compensation availability of the current QtMultimedia backend.

Since
6.10

Indicates the availability of pitch compensation of the QMediaPlayer on the current backend.

Note
Different backends may have different behavior.

For more information, see \l{QMediaPlayer::PitchCompensationAvailability}.

Since
6.10

Definition at line 1186 of file qmediaplayer.cpp.

◆ pitchCompensationChanged

void QMediaPlayer::pitchCompensationChanged ( bool )
signal

◆ play

void QMediaPlayer::play ( )
slot

\qmlmethod QtMultimedia::MediaPlayer::play()

Starts or resumes playback of the media.

Sets the \l playbackState property to PlayingState, and changes \l playing to true.

Start or resume playing the current source.

See also
pause(), stop()

Definition at line 532 of file qmediaplayer.cpp.

◆ playbackOptions()

QPlaybackOptions QMediaPlayer::playbackOptions ( ) const

Definition at line 1217 of file qmediaplayer.cpp.

◆ playbackOptionsChanged

void QMediaPlayer::playbackOptionsChanged ( )
signal

◆ playbackRate()

qreal QMediaPlayer::playbackRate ( ) const

Returns the current playback rate.

Definition at line 446 of file qmediaplayer.cpp.

◆ playbackRateChanged

void QMediaPlayer::playbackRateChanged ( qreal rate)
signal

Signals the playbackRate has changed to rate.

◆ playbackState()

QMediaPlayer::PlaybackState QMediaPlayer::playbackState ( ) const

Definition at line 316 of file qmediaplayer.cpp.

◆ playbackStateChanged

void QMediaPlayer::playbackStateChanged ( QMediaPlayer::PlaybackState newState)
signal

◆ playingChanged

void QMediaPlayer::playingChanged ( bool playing)
signal

◆ position()

qint64 QMediaPlayer::position ( ) const

Returns the current position inside the media being played back in ms.

Returns 0 if the media player doesn't have a valid media file or stream. For live streams, the duration usually changes during playback as more data becomes available.

Definition at line 357 of file qmediaplayer.cpp.

◆ positionChanged

void QMediaPlayer::positionChanged ( qint64 position)
signal

Signals the position of the content has changed to position, expressed in milliseconds.

◆ Q_REVISION

QMediaPlayer::Q_REVISION ( 6 ,
8  )
signal

◆ resetPlaybackOptions

void QMediaPlayer::resetPlaybackOptions ( )
slot

Definition at line 1230 of file qmediaplayer.cpp.

◆ seekableChanged

void QMediaPlayer::seekableChanged ( bool seekable)
signal

Signals the seekable status of the player object has changed.

◆ setActiveAudioTrack()

void QMediaPlayer::setActiveAudioTrack ( int index)

Definition at line 952 of file qmediaplayer.cpp.

◆ setActiveSubtitleTrack()

void QMediaPlayer::setActiveSubtitleTrack ( int index)

Definition at line 974 of file qmediaplayer.cpp.

◆ setActiveVideoTrack()

void QMediaPlayer::setActiveVideoTrack ( int index)

Definition at line 963 of file qmediaplayer.cpp.

◆ setAudioBufferOutput()

void QMediaPlayer::setAudioBufferOutput ( QAudioBufferOutput * output)

Definition at line 728 of file qmediaplayer.cpp.

◆ setAudioOutput()

void QMediaPlayer::setAudioOutput ( QAudioOutput * output)

Definition at line 775 of file qmediaplayer.cpp.

◆ setLoops()

void QMediaPlayer::setLoops ( int loops)

Definition at line 484 of file qmediaplayer.cpp.

◆ setPitchCompensation

void QMediaPlayer::setPitchCompensation ( bool enabled) const
slot

Sets the state (enabled or disabled) of pitch compensation.

This only has an effect if the audio pitch compensation can be configured on the backend at runtime.

Since
6.10

Definition at line 1135 of file qmediaplayer.cpp.

◆ setPlaybackOptions

void QMediaPlayer::setPlaybackOptions ( const QPlaybackOptions & options)
slot

Definition at line 1223 of file qmediaplayer.cpp.

◆ setPlaybackRate

void QMediaPlayer::setPlaybackRate ( qreal rate)
slot

Definition at line 597 of file qmediaplayer.cpp.

◆ setPosition

void QMediaPlayer::setPosition ( qint64 position)
slot

Definition at line 586 of file qmediaplayer.cpp.

◆ setSource

void QMediaPlayer::setSource ( const QUrl & source)
slot

\qmlproperty url QtMultimedia::MediaPlayer::source

This property holds the source URL of the media.

See also
QMediaPlayer::setSource()

Sets the current source.

Setting the media to a null QUrl 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. Setting the media will stop the playback.

Note
This function returns immediately after recording the specified source of the media. It does not wait for the media to finish loading and does not check for errors. Listen for the mediaStatusChanged() and error() signals to be notified when the media is loaded and when an error occurs during loading.
FFmpeg, used by the FFmpeg media backend, restricts use of nested protocols for security reasons. In controlled environments where all inputs are trusted, the list of approved protocols can be overridden using the QT_FFMPEG_PROTOCOL_WHITELIST environment variable. This environment variable is Qt's private API and can change between patch releases without notice.

Definition at line 634 of file qmediaplayer.cpp.

◆ setSourceDevice

void QMediaPlayer::setSourceDevice ( QIODevice * device,
const QUrl & sourceUrl = QUrl() )
slot

Sets the current source device.

The media data will be read from device. The sourceUrl can be provided to resolve additional information about the media, mime type etc. The device must be open and readable.

For macOS the device should also be seek-able.

Note
This function returns immediately after recording the specified source of the media. It does not wait for the media to finish loading and does not check for errors. Listen for the mediaStatusChanged() and error() signals to be notified when the media is loaded, and if an error occurs during loading.

Definition at line 663 of file qmediaplayer.cpp.

◆ setVideoOutput()

void QMediaPlayer::setVideoOutput ( QObject * output)

Definition at line 1010 of file qmediaplayer.cpp.

◆ setVideoSink()

void QMediaPlayer::setVideoSink ( QVideoSink * sink)

Sets sink to be the QVideoSink instance to retrieve video data.

Definition at line 1029 of file qmediaplayer.cpp.

◆ source()

QUrl QMediaPlayer::source ( ) const

Definition at line 287 of file qmediaplayer.cpp.

◆ sourceChanged

void QMediaPlayer::sourceChanged ( const QUrl & media)
signal

Signals that the media source has been changed to media.

◆ sourceDevice()

const QIODevice * QMediaPlayer::sourceDevice ( ) const

Returns the stream source of media data.

This is only valid if a stream was passed to setSource().

See also
setSource()

Definition at line 302 of file qmediaplayer.cpp.

◆ stop

void QMediaPlayer::stop ( )
slot

\qmlmethod QtMultimedia::MediaPlayer::stop()

Stops playback of the media.

Sets the \l playbackState property to StoppedState, and changes \l playing to false.

Stop playing, and reset the play position to the beginning.

See also
play(), pause()

Definition at line 578 of file qmediaplayer.cpp.

◆ subtitleTracks()

QList< QMediaMetaData > QMediaPlayer::subtitleTracks ( ) const

Definition at line 875 of file qmediaplayer.cpp.

◆ tracksChanged

void QMediaPlayer::tracksChanged ( )
signal

◆ videoOutput()

QObject * QMediaPlayer::videoOutput ( ) const

Definition at line 1004 of file qmediaplayer.cpp.

◆ videoOutputChanged

void QMediaPlayer::videoOutputChanged ( )
signal

◆ videoSink()

QVideoSink * QMediaPlayer::videoSink ( ) const

Returns the QVideoSink instance.

Definition at line 1039 of file qmediaplayer.cpp.

◆ videoTracks()

QList< QMediaMetaData > QMediaPlayer::videoTracks ( ) const

Definition at line 848 of file qmediaplayer.cpp.

◆ QPlatformMediaPlayer

friend class QPlatformMediaPlayer
friend

Definition at line 233 of file qmediaplayer.h.

Property Documentation

◆ activeAudioTrack

int QMediaPlayer::activeAudioTrack
readwrite

\qmlproperty int QtMultimedia::MediaPlayer::activeAudioTrack

This property holds the track number of the currently active audio track. Set to {-1} to disable audio track.

The default property value is {0}: the first audio track.

Returns the currently active audio track.

By default, the first available audio track will be chosen.

Set index to -1 to disable all audio tracks.

Definition at line 51 of file qmediaplayer.h.

◆ activeSubtitleTrack

int QMediaPlayer::activeSubtitleTrack
readwrite

Returns the currently active subtitle track.

Since
6.2 \qmlproperty int QtMultimedia::MediaPlayer::activeSubtitleTrack

This property holds the track number of the currently active subtitle track. Set to {-1} to disable subtitle track.

The default property value is {-1}: no subtitles active.

Set index to -1 to disable subtitles.

Subtitles are disabled by default.

Definition at line 55 of file qmediaplayer.h.

◆ activeVideoTrack

int QMediaPlayer::activeVideoTrack
readwrite

Returns the currently active video track.

Since
6.2 \qmlproperty int QtMultimedia::MediaPlayer::activeVideoTrack

This property holds the track number of the currently active video audio track. Set to {-1} to disable video track.

The default property value is {0}: the first video track.

By default, the first available audio track will be chosen.

Set index to -1 to disable all video tracks.

Definition at line 53 of file qmediaplayer.h.

◆ audioBufferOutput

QAudioBufferOutput * QMediaPlayer::audioBufferOutput
read

\qmlproperty QAudioBufferOutput QtMultimedia::MediaPlayer::audioBufferOutput

Since
6.8

This property holds the target audio buffer output.

Normal usage of MediaPlayer from QML should not require using this property.

See also
QMediaPlayer::audioBufferOutput()
Since
6.8

The output audio buffer used by the media player.

Sets an audio buffer output to the media player.

If \l QAudioBufferOutput is specified and the media source contains an audio stream, the media player, it will emit the signal \l{QAudioBufferOutput::audioBufferReceived} with audio buffers containing decoded audio data. At the end of the audio stream, QMediaPlayer emits an empty \l QAudioBuffer.

QMediaPlayer emits outputs audio buffers at the same time as it pushes the matching data to the audio output if it's specified. However, the sound can be played with a small delay due to audio bufferization.

The format of emitted audio buffers is taken from the specified output or from the matching audio stream if the output returns an invalid format. Emitted audio data is not scaled depending on the current playback rate.

Potential use cases of utilizing QAudioBufferOutput with QMediaPlayer might be: \list

  • Audio visualization. If the playback rate of the media player is not 1, you may scale the output image dimensions, or image update interval according to the requirements of the visualizer.
  • Any AI sound processing, e.g. voice recognition.
  • Sending the data to external audio output. Playback rate changing, synchronization with video, and manual flushing on stoping and seeking should be considered. We don't recommend using the audio buffer output for this purpose unless you have a strong reason for this. \endlist

Definition at line 45 of file qmediaplayer.h.

◆ audioOutput

QAudioOutput * QMediaPlayer::audioOutput
readwrite

\qmlproperty AudioOutput QtMultimedia::MediaPlayer::audioOutput

This property holds the target audio output. Accepts one AudioOutput elements.

See also
QMediaPlayer::setAudioOutput()

The audio output device used by the media player.

The current audio output to be used when playing back media. Setting a new audio output will replace the currently used output.

Setting this property to nullptr will disable any audio output.

Definition at line 42 of file qmediaplayer.h.

◆ audioTracks

QList<QMediaMetaData> QMediaPlayer::audioTracks
read

\qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::audioTracks

This property holds a list of metadata. Each index refers to an audio track.

The metadata holds properties describing the individual tracks. For audio tracks the \l{QMediaMetaData}{Language} is usually the most important property.

See also
mediaMetaData

Lists the set of available audio tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

Different audio tracks can for example contain audio in different languages.

Definition at line 47 of file qmediaplayer.h.

◆ bufferProgress

float QMediaPlayer::bufferProgress
read

\qmlproperty real QtMultimedia::MediaPlayer::bufferProgress

This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 (full).

Playback can start or resume only when the buffer is entirely filled. When the buffer is filled, MediaPlayer.Buffered is true. When buffer progress is between 0.0 and 1.0, MediaPlayer.Buffering is set to {true}.

A value lower than 1.0 implies that the property MediaPlayer.StalledMedia is {true}.

See also
mediaStatus

the percentage of the temporary buffer filled before playback begins or resumes, from 0. (empty) to 1. (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.

See also
mediaStatus()

Definition at line 29 of file qmediaplayer.h.

◆ duration

qint64 QMediaPlayer::duration
read

\qmlproperty int QtMultimedia::MediaPlayer::duration

This property holds the duration of the media in milliseconds.

If the media doesn't have a fixed duration (a live stream for example) this will be set to {0}.

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.

Definition at line 27 of file qmediaplayer.h.

◆ error

Error QMediaPlayer::error
read

a string describing the last error condition.

See also
error()

Definition at line 39 of file qmediaplayer.h.

◆ errorString

QString QMediaPlayer::errorString
read

\qmlproperty string QtMultimedia::MediaPlayer::errorString

This property holds a string describing the current error condition in more detail.

This property holds a string describing the current error condition in more detail.

Definition at line 40 of file qmediaplayer.h.

◆ hasAudio

bool QMediaPlayer::hasAudio
read

\qmlproperty bool QtMultimedia::MediaPlayer::hasAudio

This property holds whether the media contains audio.

This property holds whether the media contains audio.

Definition at line 30 of file qmediaplayer.h.

◆ hasVideo

bool QMediaPlayer::hasVideo
read

\qmlproperty bool QtMultimedia::MediaPlayer::hasVideo

This property holds whether the media contains video.

This property holds whether the media contains video.

Definition at line 31 of file qmediaplayer.h.

◆ loops

int QMediaPlayer::loops
readwrite

Determines how often the media is played before the player stops.

Set to QMediaPlayer::Infinite to loop the current media file forever.

The default value is 1. Setting this property to 0 has no effect.

Definition at line 35 of file qmediaplayer.h.

◆ mediaStatus

MediaStatus QMediaPlayer::mediaStatus
read

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

Definition at line 37 of file qmediaplayer.h.

◆ metaData

QMediaMetaData QMediaPlayer::metaData
read

\qmlproperty mediaMetaData QtMultimedia::MediaPlayer::metaData

Returns meta data for the current media used by the media player.

Meta data can contain information such as the title of the video or its creation date.

Note
The Windows implementation provides metadata only for media located on the local file system.

Returns meta data for the current media used by the media player.

Meta data can contain information such as the title of the video or its creation date.

Note
The Windows implementation provides metadata only for media located on the local file system.

Definition at line 38 of file qmediaplayer.h.

◆ pitchCompensation

PitchCompensationAvailability pitchCompensationAvailability READ pitchCompensationAvailability CONSTANT Q_PROPERTYbool QMediaPlayer::pitchCompensation
readwrite

\qmlproperty bool QtMultimedia::MediaPlayer::pitchCompensation

Since
6.10

This property holds whether pitch compensation is enabled.

The pitch compensation status of the media player.

Since
6.10

Indicates whether pitch compensation is enabled. When enabled, changing the playback rate will not affect the pitch of the audio signal.

Note
The pitch compensation will increase the CPU load of the QMediaPlayer.

By default is {true} if pitch compensation, is available, else {false}.

Definition at line 59 of file qmediaplayer.h.

◆ playbackOptions

QPlaybackOptions QMediaPlayer::playbackOptions
readwrite

\qmlproperty playbackOptions MediaPlayer::playbackOptions

Since
6.10

This property exposes the \l playbackOptions API that gives low-level control of media playback options. Although we strongly recommend to rely on the default settings of \l MediaPlayer, this API can be used to optimize media playback for specific use cases where the default options are not ideal.

Playback options take effect the next time \l MediaPlayer::source is changed.

Advanced playback options used to configure media playback and decoding.

Since
6.10

This property exposes the \l QPlaybackOptions API that gives low-level control of media playback options. Although we strongly recommend to rely on the default settings of \l QMediaPlayer, this API can be used to optimize media playback for specific use cases where the default options are not ideal.

Playback options take effect the next time \l QMediaPlayer::setSource() is called.

Definition at line 67 of file qmediaplayer.h.

◆ playbackRate

qreal QMediaPlayer::playbackRate
readwrite

\qmlproperty real QtMultimedia::MediaPlayer::playbackRate

This property holds the rate at which media is played at as a multiple of the normal rate.

For more information, see \l{QMediaPlayer::playbackRate}.

Defaults to {1.0}.

the playback rate of the current media.

This value is a multiplier applied to the media's standard playback rate. By default this value is 1.0, indicating that the media is playing at the standard speed. Values higher than 1.0 will increase the playback speed, while values between 0.0 and 1.0 results in slower playback. Negative playback rates are not supported.

Not all playback services support change of the playback rate. It is framework defined as to the status and quality of audio and video while fast forwarding or rewinding.

Definition at line 34 of file qmediaplayer.h.

◆ playbackState

PlaybackState QMediaPlayer::playbackState
read

Returns the \l{QMediaPlayer::}{PlaybackState}.

See also
playing

Definition at line 36 of file qmediaplayer.h.

◆ playing

bool QMediaPlayer::playing
read

\qmlproperty bool QtMultimedia::MediaPlayer::playing

Since
6.5

Indicates whether the media is currently playing.

See also
playbackState

Whether the media is playing.

Since
6.5
See also
playbackState, PlayingState

Definition at line 33 of file qmediaplayer.h.

◆ position

qint64 QMediaPlayer::position
readwrite

\qmlproperty int QtMultimedia::MediaPlayer::position

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 positionChanged() signal.

If the \l seekable property is true, this property can be set to milliseconds.

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 positionChanged() signal.

If the \l seekable property is true, this property can be set to milliseconds.

Definition at line 28 of file qmediaplayer.h.

◆ seekable

bool QMediaPlayer::seekable
read

\qmlproperty bool QtMultimedia::MediaPlayer::seekable

This property holds whether the \l position of the media can be changed.

the seek-able 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.

Definition at line 32 of file qmediaplayer.h.

◆ source

QUrl QMediaPlayer::source
readwrite

the active media source being used by the player object.

The player object will use the QUrl for selection of the content to be played.

By default this property has a null QUrl.

Setting this property to a null QUrl 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.

See also
QUrl

Definition at line 26 of file qmediaplayer.h.

◆ subtitleTracks

QList<QMediaMetaData> QMediaPlayer::subtitleTracks
read

\qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::subtitleTracks

This property holds a list of metadata. Each index refers to a subtitle track.

The metadata holds properties describing the individual tracks. For subtitle tracks the \l{QMediaMetaData}{Language} is usually the most important property.

See also
mediaMetaData

Lists the set of available subtitle tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

Definition at line 49 of file qmediaplayer.h.

◆ videoOutput

QObject * QMediaPlayer::videoOutput
readwrite

\qmlproperty VideoOutput QtMultimedia::MediaPlayer::videoOutput

This property holds the target video output. Accepts one VideoOutput elements.

See also
QMediaPlayer::setVideoOutput()

The video output to be used by the media player.

A media player can only have one video output attached, so setting this property will replace the previously connected video output.

Setting this property to nullptr will disable video output.

Definition at line 41 of file qmediaplayer.h.

◆ videoTracks

QList<QMediaMetaData> QMediaPlayer::videoTracks
read

\qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::videoTracks

This property holds a list of metadata. Each index refers to a video track.

The metadata holds properties describing the individual tracks.

See also
mediaMetaData

Lists the set of available video tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

Definition at line 48 of file qmediaplayer.h.


The documentation for this class was generated from the following files: