QMediaPlayer

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

Inheritance diagram of PySide6.QtMultimedia.QMediaPlayer

Synopsis

Functions

Slots

Signals

Detailed Description

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)
connect(player, SIGNAL(positionChanged(qint64)), self, SLOT(positionChanged(qint64)))
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.

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.

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.activeAudioTrack()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.activeSubtitleTrack()
Return type

int

This property holds Returns the currently active subtitle track..

Set index to -1 to disable subtitles.

Subtitles are disabled by default.

PySide6.QtMultimedia.QMediaPlayer.activeTracksChanged()
PySide6.QtMultimedia.QMediaPlayer.activeVideoTrack()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.audioOutput()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.audioOutputChanged()
PySide6.QtMultimedia.QMediaPlayer.audioTracks()
Return type

PySide6.QtMultimedia.QMediaPlayer.bufferProgress()
Return type

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()

PySide6.QtMultimedia.QMediaPlayer.bufferProgressChanged(progress)
Parameters

progress – float

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

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.

PySide6.QtMultimedia.QMediaPlayer.durationChanged(duration)
Parameters

duration – int

PySide6.QtMultimedia.QMediaPlayer.error()
Return type

Error

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

See also

error()

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

  • errorString – str

PySide6.QtMultimedia.QMediaPlayer.errorString()
Return type

str

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

PySide6.QtMultimedia.QMediaPlayer.hasAudio()
Return type

bool

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

PySide6.QtMultimedia.QMediaPlayer.hasAudioChanged(available)
Parameters

available – bool

PySide6.QtMultimedia.QMediaPlayer.hasVideo()
Return type

bool

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

PySide6.QtMultimedia.QMediaPlayer.hasVideoChanged(videoAvailable)
Parameters

videoAvailable – bool

PySide6.QtMultimedia.QMediaPlayer.isAvailable()
Return type

bool

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

PySide6.QtMultimedia.QMediaPlayer.isSeekable()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.loops()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.loopsChanged()
PySide6.QtMultimedia.QMediaPlayer.mediaStatus()
Return type

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

PySide6.QtMultimedia.QMediaPlayer.mediaStatusChanged(status)
Parameters

statusMediaStatus

PySide6.QtMultimedia.QMediaPlayer.metaData()
Return type

PySide6.QtMultimedia.QMediaMetaData

PySide6.QtMultimedia.QMediaPlayer.metaDataChanged()
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

This property holds the playback rate of the current media..

This value is a multiplier applied to the media’s standard play rate. By default this value is 1.0, indicating that the media is playing at the standard pace. Values higher than 1.0 will increase the rate of play. Values less than zero can be set and indicate the media should rewind at the multiplier of the standard pace.

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.

PySide6.QtMultimedia.QMediaPlayer.playbackRateChanged(rate)
Parameters

rate – float

PySide6.QtMultimedia.QMediaPlayer.playbackState()
Return type

PlaybackState

PySide6.QtMultimedia.QMediaPlayer.playbackStateChanged(newState)
Parameters

newStatePlaybackState

PySide6.QtMultimedia.QMediaPlayer.position()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.positionChanged(position)
Parameters

position – int

PySide6.QtMultimedia.QMediaPlayer.seekableChanged(seekable)
Parameters

seekable – bool

PySide6.QtMultimedia.QMediaPlayer.setActiveAudioTrack(index)
Parameters

index – 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.

PySide6.QtMultimedia.QMediaPlayer.setActiveSubtitleTrack(index)
Parameters

index – int

This property holds Returns the currently active subtitle track..

Set index to -1 to disable subtitles.

Subtitles are disabled by default.

PySide6.QtMultimedia.QMediaPlayer.setActiveVideoTrack(index)
Parameters

index – 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.

PySide6.QtMultimedia.QMediaPlayer.setAudioOutput(output)
Parameters

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

PySide6.QtMultimedia.QMediaPlayer.setLoops(loops)
Parameters

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.

PySide6.QtMultimedia.QMediaPlayer.setPlaybackRate(rate)
Parameters

rate – float

This property holds the playback rate of the current media..

This value is a multiplier applied to the media’s standard play rate. By default this value is 1.0, indicating that the media is playing at the standard pace. Values higher than 1.0 will increase the rate of play. Values less than zero can be set and indicate the media should rewind at the multiplier of the standard pace.

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.

PySide6.QtMultimedia.QMediaPlayer.setPosition(position)
Parameters

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.

PySide6.QtMultimedia.QMediaPlayer.setSource(source)
Parameters

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

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

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.

PySide6.QtMultimedia.QMediaPlayer.setVideoSink(sink)
Parameters

sinkPySide6.QtMultimedia.QVideoSink

PySide6.QtMultimedia.QMediaPlayer.source()
Return type

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

PySide6.QtMultimedia.QMediaPlayer.sourceChanged(media)
Parameters

mediaPySide6.QtCore.QUrl

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

PySide6.QtMultimedia.QMediaPlayer.tracksChanged()
PySide6.QtMultimedia.QMediaPlayer.videoOutput()
Return type

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.

PySide6.QtMultimedia.QMediaPlayer.videoOutputChanged()
PySide6.QtMultimedia.QMediaPlayer.videoSink()
Return type

PySide6.QtMultimedia.QVideoSink

PySide6.QtMultimedia.QMediaPlayer.videoTracks()
Return type