QMediaPlayer

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

Inheritance diagram of PySide6.QtMultimedia.QMediaPlayer

Synopsis

Functions

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 = new QMediaPlayer;
audioOutput = new QAudioOutput;
player->setAudioOutput(audioOutput);
connect(player, SIGNAL(positionChanged(qint64)), this, 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

PySide6.QtMultimedia.QMediaPlayer.activeSubtitleTrack()
Return type

int

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

int

PySide6.QtMultimedia.QMediaPlayer.audioOutput()
Return type

PySide6.QtMultimedia.QAudioOutput

See also

setAudioOutput()

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

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.

PySide6.QtMultimedia.QMediaPlayer.bufferProgress()
Return type

float

Returns a number betwee 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.

will always return 1 for local files.

PySide6.QtMultimedia.QMediaPlayer.bufferProgressChanged(progress)
Parameters

progress – float

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

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.

PySide6.QtMultimedia.QMediaPlayer.durationChanged(duration)
Parameters

duration – int

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

PySide6.QtMultimedia.QMediaPlayer.error()
Return type

Error

Returns the current error state.

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

PySide6.QtMultimedia.QMediaPlayer.hasAudio()
Return type

bool

PySide6.QtMultimedia.QMediaPlayer.hasAudioChanged(available)
Parameters

available – bool

Signals the availability of audio content has changed to available.

PySide6.QtMultimedia.QMediaPlayer.hasVideo()
Return type

bool

PySide6.QtMultimedia.QMediaPlayer.hasVideoChanged(videoAvailable)
Parameters

videoAvailable – bool

Signals the availability of visual content has changed to videoAvailable.

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

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

See also

position

PySide6.QtMultimedia.QMediaPlayer.mediaStatus()
Return type

MediaStatus

PySide6.QtMultimedia.QMediaPlayer.mediaStatusChanged(status)
Parameters

statusMediaStatus

Signals that the status of the current media has changed.

See also

mediaStatus()

PySide6.QtMultimedia.QMediaPlayer.metaData()
Return type

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.

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

Returns the current playback rate.

PySide6.QtMultimedia.QMediaPlayer.playbackRateChanged(rate)
Parameters

rate – float

Signals the playbackRate has changed to rate.

PySide6.QtMultimedia.QMediaPlayer.playbackState()
Return type

PlaybackState

PySide6.QtMultimedia.QMediaPlayer.playbackStateChanged(newState)
Parameters

newStatePlaybackState

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

PySide6.QtMultimedia.QMediaPlayer.positionChanged(position)
Parameters

position – int

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

PySide6.QtMultimedia.QMediaPlayer.seekableChanged(seekable)
Parameters

seekable – bool

Signals the seekable status of the player object has changed.

PySide6.QtMultimedia.QMediaPlayer.setActiveAudioTrack(index)
Parameters

index – int

PySide6.QtMultimedia.QMediaPlayer.setActiveSubtitleTrack(index)
Parameters

index – int

PySide6.QtMultimedia.QMediaPlayer.setActiveVideoTrack(index)
Parameters

index – int

PySide6.QtMultimedia.QMediaPlayer.setAudioOutput(output)
Parameters

outputPySide6.QtMultimedia.QAudioOutput

See also

audioOutput()

PySide6.QtMultimedia.QMediaPlayer.setPlaybackRate(rate)
Parameters

rate – float

See also

playbackRate()

PySide6.QtMultimedia.QMediaPlayer.setPosition(position)
Parameters

position – int

See also

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

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

PySide6.QtMultimedia.QMediaPlayer.setVideoSink(sink)
Parameters

sinkPySide6.QtMultimedia.QVideoSink

PySide6.QtMultimedia.QMediaPlayer.source()
Return type

PySide6.QtCore.QUrl

See also

setSource()

PySide6.QtMultimedia.QMediaPlayer.sourceChanged(media)
Parameters

mediaPySide6.QtCore.QUrl

Signals that the media source has been changed to media.

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

Lists the set of available subtitle tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.

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

PySide6.QtCore.QObject

See also

setVideoOutput()

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

PySide6.QtMultimedia.QVideoSink

PySide6.QtMultimedia.QMediaPlayer.videoTracks()
Return type

Lists the set of available video tracks inside the media.

The QMediaMetaData returned describes the properties of individual tracks.