Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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...
 

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.
 
- 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 ()
 
void tracksChanged ()
 
void activeTracksChanged ()
 
void errorChanged ()
 
void errorOccurred (QMediaPlayer::Error error, const QString &errorString)
 \qmlsignal QtMultimedia::MediaPlayer::errorOccurred(error, errorString)
 
- 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 ()
 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 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
 
- 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 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
 
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.
 
- 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 22 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 77 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 87 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 64 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 56 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 220 of file qmediaplayer.cpp.

References d, QPlatformMediaIntegration::instance(), qWarning, and ResourceError.

+ Here is the call graph for this function:

◆ ~QMediaPlayer()

QMediaPlayer::~QMediaPlayer ( )

Destroys the player object.

Definition at line 240 of file qmediaplayer.cpp.

References d, and setAudioOutput().

+ Here is the call graph for this function:

Member Function Documentation

◆ activeAudioTrack()

int QMediaPlayer::activeAudioTrack ( ) const

Definition at line 787 of file qmediaplayer.cpp.

References QPlatformMediaPlayer::AudioStream, and d.

◆ activeSubtitleTrack()

int QMediaPlayer::activeSubtitleTrack ( ) const

Definition at line 835 of file qmediaplayer.cpp.

References d, and QPlatformMediaPlayer::SubtitleStream.

◆ activeTracksChanged

void QMediaPlayer::activeTracksChanged ( )
signal

Referenced by QPlatformMediaPlayer::activeTracksChanged().

+ Here is the caller graph for this function:

◆ activeVideoTrack()

int QMediaPlayer::activeVideoTrack ( ) const

Definition at line 811 of file qmediaplayer.cpp.

References d, and QPlatformMediaPlayer::VideoStream.

◆ audioOutput()

QAudioOutput * QMediaPlayer::audioOutput ( ) const

Definition at line 683 of file qmediaplayer.cpp.

References d.

◆ audioOutputChanged

void QMediaPlayer::audioOutputChanged ( )
signal

Referenced by setAudioOutput().

+ Here is the caller graph for this function:

◆ audioTracks()

QList< QMediaMetaData > QMediaPlayer::audioTracks ( ) const

Definition at line 712 of file qmediaplayer.cpp.

References QPlatformMediaPlayer::AudioStream, and d.

◆ 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 357 of file qmediaplayer.cpp.

References d.

◆ 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 342 of file qmediaplayer.cpp.

References d.

◆ bufferProgressChanged

void QMediaPlayer::bufferProgressChanged ( float progress)
signal

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

Referenced by QPlatformMediaPlayer::bufferProgressChanged().

+ Here is the caller graph for this function:

◆ 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 314 of file qmediaplayer.cpp.

References d.

◆ durationChanged

void QMediaPlayer::durationChanged ( qint64 duration)
signal

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

Referenced by QQuickMediaPlayer::QQuickMediaPlayer(), and QPlatformMediaPlayer::durationChanged().

+ Here is the caller graph for this function:

◆ error()

QMediaPlayer::Error QMediaPlayer::error ( ) const

Returns the current error state.

Definition at line 466 of file qmediaplayer.cpp.

◆ errorChanged

void QMediaPlayer::errorChanged ( )
signal

◆ errorOccurred

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 483 of file qmediaplayer.cpp.

◆ hasAudio()

bool QMediaPlayer::hasAudio ( ) const

Definition at line 373 of file qmediaplayer.cpp.

References d.

◆ hasAudioChanged

void QMediaPlayer::hasAudioChanged ( bool available)
signal

Signals the availability of audio content has changed to available.

Referenced by QPlatformMediaPlayer::audioAvailableChanged().

+ Here is the caller graph for this function:

◆ hasVideo()

bool QMediaPlayer::hasVideo ( ) const

Definition at line 389 of file qmediaplayer.cpp.

References d.

◆ hasVideoChanged

void QMediaPlayer::hasVideoChanged ( bool videoAvailable)
signal

Signals the availability of visual content has changed to videoAvailable.

Referenced by QPlatformMediaPlayer::videoAvailableChanged().

+ Here is the caller graph for this function:

◆ isAvailable()

bool QMediaPlayer::isAvailable ( ) const

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

Definition at line 955 of file qmediaplayer.cpp.

References d.

◆ isPlaying()

bool QMediaPlayer::isPlaying ( ) const

Definition at line 407 of file qmediaplayer.cpp.

References d, and PlayingState.

◆ 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 401 of file qmediaplayer.cpp.

References d.

◆ 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 448 of file qmediaplayer.cpp.

References d.

◆ loopsChanged

void QMediaPlayer::loopsChanged ( )
signal

Referenced by QPlatformMediaPlayer::setLoops().

+ Here is the caller graph for this function:

◆ mediaStatus()

QMediaPlayer::MediaStatus QMediaPlayer::mediaStatus ( ) const

Definition at line 301 of file qmediaplayer.cpp.

References d, and NoMedia.

◆ mediaStatusChanged

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

Signals that the status of the current media has changed.

See also
mediaStatus()

Referenced by QQuickMediaPlayer::QQuickMediaPlayer().

+ Here is the caller graph for this function:

◆ metaData()

QMediaMetaData QMediaPlayer::metaData ( ) const

Definition at line 982 of file qmediaplayer.cpp.

References d.

◆ metaDataChanged

void QMediaPlayer::metaDataChanged ( )
signal

Referenced by QPlatformMediaPlayer::metaDataChanged().

+ Here is the caller graph for this function:

◆ 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 529 of file qmediaplayer.cpp.

References d.

◆ 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 502 of file qmediaplayer.cpp.

References d, and NoError.

Referenced by VideoExample::VideoGraphicsItem(), and VideoExample::VideoWidget().

+ Here is the caller graph for this function:

◆ playbackRate()

qreal QMediaPlayer::playbackRate ( ) const

Returns the current playback rate.

Definition at line 416 of file qmediaplayer.cpp.

References d.

◆ playbackRateChanged

void QMediaPlayer::playbackRateChanged ( qreal rate)
signal

Signals the playbackRate has changed to rate.

Referenced by QPlatformMediaPlayer::playbackRateChanged().

+ Here is the caller graph for this function:

◆ playbackState()

QMediaPlayer::PlaybackState QMediaPlayer::playbackState ( ) const

Definition at line 286 of file qmediaplayer.cpp.

References d, and EndOfMedia.

◆ 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 327 of file qmediaplayer.cpp.

References d.

◆ positionChanged

void QMediaPlayer::positionChanged ( qint64 position)
signal

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

Referenced by QQuickMediaPlayer::QQuickMediaPlayer(), and QPlatformMediaPlayer::positionChanged().

+ Here is the caller graph for this function:

◆ seekableChanged

void QMediaPlayer::seekableChanged ( bool seekable)
signal

Signals the seekable status of the player object has changed.

Referenced by QPlatformMediaPlayer::seekableChanged().

+ Here is the caller graph for this function:

◆ setActiveAudioTrack()

void QMediaPlayer::setActiveAudioTrack ( int index)

Definition at line 841 of file qmediaplayer.cpp.

References activeAudioTrack, QPlatformMediaPlayer::AudioStream, and d.

◆ setActiveSubtitleTrack()

void QMediaPlayer::setActiveSubtitleTrack ( int index)

Definition at line 863 of file qmediaplayer.cpp.

References activeSubtitleTrack, d, and QPlatformMediaPlayer::SubtitleStream.

◆ setActiveVideoTrack()

void QMediaPlayer::setActiveVideoTrack ( int index)

Definition at line 852 of file qmediaplayer.cpp.

References activeVideoTrack, d, and QPlatformMediaPlayer::VideoStream.

◆ setAudioOutput()

void QMediaPlayer::setAudioOutput ( QAudioOutput * output)

Definition at line 664 of file qmediaplayer.cpp.

References audioOutputChanged(), d, emit, output, and setAudioOutput().

Referenced by ~QMediaPlayer(), and setAudioOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLoops()

void QMediaPlayer::setLoops ( int loops)

Definition at line 454 of file qmediaplayer.cpp.

References d, and loops.

◆ setPlaybackRate

void QMediaPlayer::setPlaybackRate ( qreal rate)
slot

Definition at line 570 of file qmediaplayer.cpp.

References d.

◆ setPosition

void QMediaPlayer::setPosition ( qint64 position)
slot

Definition at line 559 of file qmediaplayer.cpp.

References d, position, and qMax().

+ Here is the call graph for this function:

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

Definition at line 601 of file qmediaplayer.cpp.

References d, emit, source, sourceChanged(), and stop().

Referenced by QQuickMediaPlayer::qmlSetSource(), VideoExample::VideoGraphicsItem(), and VideoExample::VideoWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 630 of file qmediaplayer.cpp.

References d, device, emit, sourceChanged(), and stop().

+ Here is the call graph for this function:

◆ setVideoOutput()

void QMediaPlayer::setVideoOutput ( QObject * output)

Definition at line 899 of file qmediaplayer.cpp.

References d, mo, output, and Q_RETURN_ARG.

Referenced by VideoExample::VideoGraphicsItem(), and VideoExample::VideoWidget().

+ Here is the caller graph for this function:

◆ setVideoSink()

void QMediaPlayer::setVideoSink ( QVideoSink * sink)

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

Definition at line 918 of file qmediaplayer.cpp.

References d.

Referenced by QVideoSinkPrivate::unregisterSource().

+ Here is the caller graph for this function:

◆ source()

QUrl QMediaPlayer::source ( ) const

Definition at line 257 of file qmediaplayer.cpp.

References d.

◆ sourceChanged

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

Signals that the media source has been changed to media.

Referenced by setSource(), and setSourceDevice().

+ Here is the caller graph for this function:

◆ 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 272 of file qmediaplayer.cpp.

References d.

◆ 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 551 of file qmediaplayer.cpp.

References d.

Referenced by setSource(), setSourceDevice(), and VideoExample::VideoWidget().

+ Here is the caller graph for this function:

◆ subtitleTracks()

QList< QMediaMetaData > QMediaPlayer::subtitleTracks ( ) const

Definition at line 764 of file qmediaplayer.cpp.

References d, and QPlatformMediaPlayer::SubtitleStream.

◆ tracksChanged

void QMediaPlayer::tracksChanged ( )
signal

Referenced by QPlatformMediaPlayer::tracksChanged().

+ Here is the caller graph for this function:

◆ videoOutput()

QObject * QMediaPlayer::videoOutput ( ) const

Definition at line 893 of file qmediaplayer.cpp.

References d.

◆ videoOutputChanged

void QMediaPlayer::videoOutputChanged ( )
signal

◆ videoSink()

QVideoSink * QMediaPlayer::videoSink ( ) const

Returns the QVideoSink instance.

Definition at line 928 of file qmediaplayer.cpp.

References d.

◆ videoTracks()

QList< QMediaMetaData > QMediaPlayer::videoTracks ( ) const

Definition at line 737 of file qmediaplayer.cpp.

References d, and QPlatformMediaPlayer::VideoStream.

Friends And Related Symbol Documentation

◆ QPlatformMediaPlayer

friend class QPlatformMediaPlayer
friend

Definition at line 190 of file qmediaplayer.h.

Property Documentation

◆ activeAudioTrack

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 48 of file qmediaplayer.h.

Referenced by setActiveAudioTrack().

◆ activeSubtitleTrack

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 52 of file qmediaplayer.h.

Referenced by setActiveSubtitleTrack().

◆ activeVideoTrack

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 50 of file qmediaplayer.h.

Referenced by setActiveVideoTrack().

◆ audioOutput

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 41 of file qmediaplayer.h.

◆ audioTracks

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 44 of file qmediaplayer.h.

◆ bufferProgress

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 28 of file qmediaplayer.h.

◆ duration

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 26 of file qmediaplayer.h.

◆ error

QMediaPlayer::error
read

a string describing the last error condition.

See also
error()

Definition at line 38 of file qmediaplayer.h.

◆ errorString

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 39 of file qmediaplayer.h.

◆ hasAudio

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 29 of file qmediaplayer.h.

◆ hasVideo

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 30 of file qmediaplayer.h.

◆ loops

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 34 of file qmediaplayer.h.

Referenced by setLoops().

◆ 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 36 of file qmediaplayer.h.

◆ metaData

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 37 of file qmediaplayer.h.

◆ playbackRate

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 33 of file qmediaplayer.h.

◆ playbackState

QMediaPlayer::playbackState
read

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

See also
playing

Definition at line 35 of file qmediaplayer.h.

◆ playing

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 32 of file qmediaplayer.h.

◆ position

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 27 of file qmediaplayer.h.

Referenced by setPosition().

◆ seekable

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 31 of file qmediaplayer.h.

◆ source

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 25 of file qmediaplayer.h.

Referenced by setSource().

◆ subtitleTracks

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 46 of file qmediaplayer.h.

◆ videoOutput

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 40 of file qmediaplayer.h.

◆ videoTracks

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 45 of file qmediaplayer.h.


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