QMediaPlayer#

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

Inheritance diagram of PySide6.QtMultimedia.QMediaPlayer

Synopsis#

Properties#

Functions#

Slots#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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.

player = QMediaPlayer()
audioOutput = QAudioOutput()
player.setAudioOutput(audioOutput)
player.positionChanged.connect(self.positionChanged)
player.setSource(QUrl.fromLocalFile("/Users/me/Music/coolsong.mp3"))
audioOutput.setVolume(50)
player.play()

QVideoWidget can be used with QMediaPlayer for video rendering.

See also

QVideoWidget

class PySide6.QtMultimedia.QMediaPlayer([parent=None])#
Parameters:

parentPySide6.QtCore.QObject

Constructs a QMediaPlayer instance as a child of parent.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtMultimedia.QMediaPlayer.activeAudioTrack: int#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.activeSubtitleTrack: int#

This property holds Returns the currently active subtitle track..

Set index to -1 to disable subtitles.

Subtitles are disabled by default.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.activeVideoTrack: int#

This property holds Returns the currently active video track..

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

Set index to -1 to disable all video tracks.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.audioOutput: PySide6.QtMultimedia.QAudioOutput#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.audioTracks: list of QMediaMetaData#

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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.bufferProgress: float#

This property holds 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()

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.duration: int#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.error: Error#

This property holds a string describing the last error condition..

See also

error()

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.errorString: str#

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

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.hasAudio: bool#

This property holds This property holds whether the media contains audio..

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.hasVideo: bool#

This property holds This property holds whether the media contains video..

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.loops: int#

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

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

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.mediaStatus: MediaStatus#

This property holds 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 NoMedia

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.metaData: PySide6.QtMultimedia.QMediaMetaData#

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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.playbackRate: float#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.playbackState: PlaybackState#

Returns the PlaybackState .

See also

playing

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.playing: bool#

This property holds Whether the media is playing..

See also

playbackState PlayingState

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.position: int#

This property holds 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 seekable property is true, this property can be set to milliseconds.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.seekable: bool#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.source: PySide6.QtCore.QUrl#

This property holds 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

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.subtitleTracks: list of QMediaMetaData#

Lists the set of available subtitle tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.videoOutput: PySide6.QtCore.QObject#

This property holds 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.

Access functions:
property PᅟySide6.QtMultimedia.QMediaPlayer.videoTracks: list of QMediaMetaData#

Lists the set of available video tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

Access functions:
PySide6.QtMultimedia.QMediaPlayer.PlaybackState#

Defines the current state of a media player.

Constant

Description

QMediaPlayer.StoppedState

The media player is not playing content, playback will begin from the start of the current track.

QMediaPlayer.PlayingState

The media player is currently playing content. This indicates the same as the playing property.

QMediaPlayer.PausedState

The media player has paused playback, playback of the current track will resume from the position the player was paused at.

New in version 6.1.

PySide6.QtMultimedia.QMediaPlayer.MediaStatus#

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

Constant

Description

QMediaPlayer.NoMedia

The is no current media. The player is in the StoppedState .

QMediaPlayer.LoadingMedia

The current media is being loaded. The player may be in any state.

QMediaPlayer.LoadedMedia

The current media has been loaded. The player is in the StoppedState .

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

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

QMediaPlayer.BufferedMedia

The player has fully buffered the current media. The player is in the PlayingState or PausedState .

QMediaPlayer.EndOfMedia

Playback has reached the end of the current media. The player is in the StoppedState .

QMediaPlayer.InvalidMedia

The current media cannot be played. The player is in the StoppedState .

PySide6.QtMultimedia.QMediaPlayer.Error#

Defines a media player error condition.

Constant

Description

QMediaPlayer.NoError

No error has occurred.

QMediaPlayer.ResourceError

A media resource couldn’t be resolved.

QMediaPlayer.FormatError

The format of a media resource isn’t (fully) supported. Playback may still be possible, but without an audio or video component.

QMediaPlayer.NetworkError

A network error occurred.

QMediaPlayer.AccessDeniedError

There are not the appropriate permissions to play a media resource.

PySide6.QtMultimedia.QMediaPlayer.Loops#

(inherits enum.IntEnum) Some predefined constants for the loops property.

Constant

Description

QMediaPlayer.Infinite

Loop forever.

QMediaPlayer.Once

Play the media once (the default).

New in version 6.2.3.

PySide6.QtMultimedia.QMediaPlayer.activeAudioTrack()#
Return type:

int

Getter of property activeAudioTrack .

PySide6.QtMultimedia.QMediaPlayer.activeSubtitleTrack()#
Return type:

int

Getter of property activeSubtitleTrack .

PySide6.QtMultimedia.QMediaPlayer.activeTracksChanged()#

Notification signal of property activeAudioTrack .

PySide6.QtMultimedia.QMediaPlayer.activeVideoTrack()#
Return type:

int

Getter of property activeVideoTrack .

PySide6.QtMultimedia.QMediaPlayer.audioOutput()#
Return type:

PySide6.QtMultimedia.QAudioOutput

See also

setAudioOutput()

Getter of property audioOutput .

PySide6.QtMultimedia.QMediaPlayer.audioOutputChanged()#

Notification signal of property audioOutput .

PySide6.QtMultimedia.QMediaPlayer.audioTracks()#
Return type:

.list of QMediaMetaData

Getter of property audioTracks .

PySide6.QtMultimedia.QMediaPlayer.bufferProgress()#
Return type:

float

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.

Getter of property bufferProgress .

PySide6.QtMultimedia.QMediaPlayer.bufferProgressChanged(progress)#
Parameters:

progress – float

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

Notification signal of property bufferProgress .

PySide6.QtMultimedia.QMediaPlayer.bufferedTimeRange()#
Return type:

PySide6.QtMultimedia.QMediaTimeRange

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

PySide6.QtMultimedia.QMediaPlayer.duration()#
Return type:

int

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.

Getter of property duration .

PySide6.QtMultimedia.QMediaPlayer.durationChanged(duration)#
Parameters:

duration – int

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

Notification signal of property duration .

PySide6.QtMultimedia.QMediaPlayer.error()#
Return type:

Error

Returns the current error state.

Getter of property error .

PySide6.QtMultimedia.QMediaPlayer.errorChanged()#

Notification signal of property error .

PySide6.QtMultimedia.QMediaPlayer.errorOccurred(error, errorString)#
Parameters:
  • errorError

  • errorString – str

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

See also

errorString()

PySide6.QtMultimedia.QMediaPlayer.errorString()#
Return type:

str

Getter of property errorString .

PySide6.QtMultimedia.QMediaPlayer.hasAudio()#
Return type:

bool

Getter of property hasAudio .

PySide6.QtMultimedia.QMediaPlayer.hasAudioChanged(available)#
Parameters:

available – bool

Signals the availability of audio content has changed to available.

Notification signal of property hasAudio .

PySide6.QtMultimedia.QMediaPlayer.hasVideo()#
Return type:

bool

Getter of property hasVideo .

PySide6.QtMultimedia.QMediaPlayer.hasVideoChanged(videoAvailable)#
Parameters:

videoAvailable – bool

Signals the availability of visual content has changed to videoAvailable.

Notification signal of property hasVideo .

PySide6.QtMultimedia.QMediaPlayer.isAvailable()#
Return type:

bool

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

PySide6.QtMultimedia.QMediaPlayer.isPlaying()#
Return type:

bool

Getter of property playing .

PySide6.QtMultimedia.QMediaPlayer.isSeekable()#
Return type:

bool

Returns true if the media is seekable. Most file based media files are seekable, but live streams usually are not.

See also

position

Getter of property seekable .

PySide6.QtMultimedia.QMediaPlayer.loops()#
Return type:

int

See also

setLoops()

Getter of property loops .

PySide6.QtMultimedia.QMediaPlayer.loopsChanged()#

Notification signal of property loops .

PySide6.QtMultimedia.QMediaPlayer.mediaStatus()#
Return type:

MediaStatus

Getter of property mediaStatus .

PySide6.QtMultimedia.QMediaPlayer.mediaStatusChanged(status)#
Parameters:

statusMediaStatus

Signals that the status of the current media has changed.

See also

mediaStatus()

Notification signal of property mediaStatus .

PySide6.QtMultimedia.QMediaPlayer.metaData()#
Return type:

PySide6.QtMultimedia.QMediaMetaData

Getter of property metaData .

PySide6.QtMultimedia.QMediaPlayer.metaDataChanged()#

Notification signal of property metaData .

PySide6.QtMultimedia.QMediaPlayer.pause()#

Pause playing the current source.

See also

play() stop()

PySide6.QtMultimedia.QMediaPlayer.play()#

Start or resume playing the current source.

See also

pause() stop()

PySide6.QtMultimedia.QMediaPlayer.playbackRate()#
Return type:

float

Returns the current playback rate.

Getter of property playbackRate .

PySide6.QtMultimedia.QMediaPlayer.playbackRateChanged(rate)#
Parameters:

rate – float

Signals the playbackRate has changed to rate.

Notification signal of property playbackRate .

PySide6.QtMultimedia.QMediaPlayer.playbackState()#
Return type:

PlaybackState

Getter of property playbackState .

PySide6.QtMultimedia.QMediaPlayer.playbackStateChanged(newState)#
Parameters:

newStatePlaybackState

Notification signal of property playbackState .

PySide6.QtMultimedia.QMediaPlayer.playingChanged(playing)#
Parameters:

playing – bool

Notification signal of property playing .

PySide6.QtMultimedia.QMediaPlayer.position()#
Return type:

int

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.

See also

setPosition()

Getter of property position .

PySide6.QtMultimedia.QMediaPlayer.positionChanged(position)#
Parameters:

position – int

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

Notification signal of property position .

PySide6.QtMultimedia.QMediaPlayer.seekableChanged(seekable)#
Parameters:

seekable – bool

Signals the seekable status of the player object has changed.

Notification signal of property seekable .

PySide6.QtMultimedia.QMediaPlayer.setActiveAudioTrack(index)#
Parameters:

index – int

Setter of property activeAudioTrack .

PySide6.QtMultimedia.QMediaPlayer.setActiveSubtitleTrack(index)#
Parameters:

index – int

Setter of property activeSubtitleTrack .

PySide6.QtMultimedia.QMediaPlayer.setActiveVideoTrack(index)#
Parameters:

index – int

Setter of property activeVideoTrack .

PySide6.QtMultimedia.QMediaPlayer.setAudioOutput(output)#
Parameters:

outputPySide6.QtMultimedia.QAudioOutput

See also

audioOutput()

Setter of property audioOutput .

PySide6.QtMultimedia.QMediaPlayer.setLoops(loops)#
Parameters:

loops – int

See also

loops()

Setter of property loops .

PySide6.QtMultimedia.QMediaPlayer.setPlaybackRate(rate)#
Parameters:

rate – float

See also

playbackRate()

Setter of property playbackRate .

PySide6.QtMultimedia.QMediaPlayer.setPosition(position)#
Parameters:

position – int

See also

position()

Setter of property position .

PySide6.QtMultimedia.QMediaPlayer.setSource(source)#
Parameters:

sourcePySide6.QtCore.QUrl

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.

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.

See also

source()

Setter of property source .

PySide6.QtMultimedia.QMediaPlayer.setSourceDevice(device[, sourceUrl=QUrl()])#
Parameters:

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.

See also

sourceDevice()

PySide6.QtMultimedia.QMediaPlayer.setVideoOutput(arg__1)#
Parameters:

arg__1PySide6.QtCore.QObject

See also

videoOutput()

Setter of property videoOutput .

PySide6.QtMultimedia.QMediaPlayer.setVideoSink(sink)#
Parameters:

sinkPySide6.QtMultimedia.QVideoSink

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

See also

videoSink()

PySide6.QtMultimedia.QMediaPlayer.source()#
Return type:

PySide6.QtCore.QUrl

See also

setSource()

Getter of property source .

PySide6.QtMultimedia.QMediaPlayer.sourceChanged(media)#
Parameters:

mediaPySide6.QtCore.QUrl

Signals that the media source has been changed to media.

Notification signal of property source .

PySide6.QtMultimedia.QMediaPlayer.sourceDevice()#
Return type:

PySide6.QtCore.QIODevice

Returns the stream source of media data.

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

PySide6.QtMultimedia.QMediaPlayer.stop()#

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

See also

play() pause()

PySide6.QtMultimedia.QMediaPlayer.subtitleTracks()#
Return type:

.list of QMediaMetaData

Getter of property subtitleTracks .

PySide6.QtMultimedia.QMediaPlayer.tracksChanged()#

Notification signal of property audioTracks .

PySide6.QtMultimedia.QMediaPlayer.videoOutput()#
Return type:

PySide6.QtCore.QObject

See also

setVideoOutput()

Getter of property videoOutput .

PySide6.QtMultimedia.QMediaPlayer.videoOutputChanged()#

Notification signal of property videoOutput .

PySide6.QtMultimedia.QMediaPlayer.videoSink()#
Return type:

PySide6.QtMultimedia.QVideoSink

Returns the QVideoSink instance.

See also

setVideoSink()

PySide6.QtMultimedia.QMediaPlayer.videoTracks()#
Return type:

.list of QMediaMetaData

Getter of property videoTracks .