PySide6.QtMultimedia.QMediaPlayer¶
- class QMediaPlayer¶
- The - QMediaPlayerclass allows the playing of a media files. More…- Synopsis¶- Properties¶- activeAudioTrackᅟ- Returns the currently active audio track
- activeSubtitleTrackᅟ- Returns the currently active subtitle track
- activeVideoTrackᅟ- Returns the currently active video track
- audioBufferOutputᅟ- Output audio buffer used by the media player
- audioOutputᅟ- Audio output device used by the media player
- bufferProgressᅟ- The percentage of the temporary buffer filled before playback begins or resumes, from 0. (empty) to 1. (full)
- durationᅟ- The duration of the current media
- errorᅟ- String describing the last error condition
- errorStringᅟ- This property holds a string describing the current error condition in more detail
- hasAudioᅟ- This property holds whether the media contains audio
- hasVideoᅟ- This property holds whether the media contains video
- mediaStatusᅟ- The status of the current media stream
- playbackRateᅟ- The playback rate of the current media
- playingᅟ- Whether the media is playing
- positionᅟ- The playback position of the current media
- seekableᅟ- The seek-able status of the current media
- sourceᅟ- The active media source being used by the player object
- videoOutputᅟ- Video output to be used by the media player
 - Methods¶- def - __init__()
- def - audioOutput()
- def - audioTracks()
- def - bufferProgress()
- def - duration()
- def - error()
- def - errorString()
- def - hasAudio()
- def - hasVideo()
- def - isAvailable()
- def - isPlaying()
- def - isSeekable()
- def - loops()
- def - mediaStatus()
- def - metaData()
- def - playbackRate()
- def - playbackState()
- def - position()
- def - setAudioOutput()
- def - setLoops()
- def - setVideoOutput()
- def - setVideoSink()
- def - source()
- def - sourceDevice()
- def - subtitleTracks()
- def - videoOutput()
- def - videoSink()
- def - videoTracks()
 - Slots¶- def - pause()
- def - play()
- def - setPosition()
- def - setSource()
- def - stop()
 - Signals¶
- def - errorChanged()
- def - errorOccurred()
- def - loopsChanged()
- def - playingChanged()
- def - sourceChanged()
- def - tracksChanged()
 - 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 - QMediaPlayerclass 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() - QVideoWidgetcan be used with- QMediaPlayerfor video rendering.- See also - class 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 - playingproperty.- QMediaPlayer.PausedState - The media player has paused playback, playback of the current track will resume from the position the player was paused at. - Added in version 6.1. 
 - class 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 - PlayingStateor- 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 - PlayingStateor- PausedState.- QMediaPlayer.BufferedMedia - The player has fully buffered the current media. The player is in the - PlayingStateor- 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.
 - class 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. 
 - class Loops¶
- (inherits - enum.IntEnum) Some predefined constants for the- loopsproperty.- Constant - Description - QMediaPlayer.Infinite - Loop forever. - QMediaPlayer.Once - Play the media once (the default). - Added in version 6.2.3. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property activeAudioTrackᅟ: int¶
 - This property holds Returns the currently active audio track.. - By default, the first available audio track will be chosen. - Set - indexto- -1to disable all audio tracks.- Access functions:
 - property activeSubtitleTrackᅟ: int¶
 - This property holds Returns the currently active subtitle track.. - Set - indexto- -1to disable subtitles.- Subtitles are disabled by default. - Access functions:
 - property activeVideoTrackᅟ: int¶
 - This property holds Returns the currently active video track.. - By default, the first available audio track will be chosen. - Set - indexto- -1to disable all video tracks.- Access functions:
 - property audioBufferOutputᅟ: QAudioBufferOutput¶
 - This property holds The output audio buffer used by the media player.. - Sets an audio buffer - outputto the media player.- If - QAudioBufferOutputis specified and the media source contains an audio stream, the media player, it will emit the signal- audioBufferReceivedwith audio buffers containing decoded audio data. At the end of the audio stream,- QMediaPlayeremits an empty- QAudioBuffer.- QMediaPlayeremits outputs audio buffers at the same time as it pushes the matching data to the audio output if it’s specified. However, the sound can be played with a small delay due to audio bufferization.- The format of emitted audio buffers is taken from the specified - outputor from the matching audio stream if the- outputreturns an invalid format. Emitted audio data is not scaled depending on the current playback rate.- Potential use cases of utilizing - QAudioBufferOutputwith- QMediaPlayermight be:- Audio visualization. If the playback rate of the media player is not - 1, you may scale the output image dimensions, or image update interval according to the requirements of the visualizer.
- Any AI sound processing, e.g. voice recognition. 
- Sending the data to external audio output. Playback rate changing, synchronization with video, and manual flushing on stoping and seeking should be considered. We don’t recommend using the audio buffer output for this purpose unless you have a strong reason for this. 
 - Access functions:
 - property audioOutputᅟ: 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 - nullptrwill disable any audio output.- Access functions:
 - property audioTracksᅟ: list of QMediaMetaData¶
 - Lists the set of available audio tracks inside the media. - The - QMediaMetaDatareturned describes the properties of individual tracks.- Different audio tracks can for example contain audio in different languages. - Access functions:
- Signal - tracksChanged()
 
 - property 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- BufferedMediaor- BufferingMedia. If the value is anything lower than- 100,- mediaStatus()will return- StalledMedia.- See also - Access functions:
 - property 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 - QMediaPlayerobject and may not be available when initial playback begins, connect to the- durationChanged()signal to receive status notifications.- Access functions:
- Signal - durationChanged()
 
 - property errorᅟ: QMediaPlayer.Error¶
 - This property holds a string describing the last error condition.. - See also - Access functions:
- Signal - errorChanged()
 
 - property errorStringᅟ: str¶
 - This property holds This property holds a string describing the current error condition in more detail.. - Access functions:
- Signal - errorChanged()
 
 - property hasAudioᅟ: bool¶
 - This property holds This property holds whether the media contains audio.. - Access functions:
- Signal - hasAudioChanged()
 
 - property hasVideoᅟ: bool¶
 - This property holds This property holds whether the media contains video.. - Access functions:
- Signal - hasVideoChanged()
 
 - property loopsᅟ: int¶
 - Determines how often the media is played before the player stops. Set to - Infiniteto loop the current media file forever.- The default value is - 1. Setting this property to- 0has no effect.- Access functions:
- Signal - loopsChanged()
 
 - property mediaStatusᅟ: QMediaPlayer.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 metaDataᅟ: 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:
- Signal - metaDataChanged()
 
 - property 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 playbackStateᅟ: QMediaPlayer.PlaybackState¶
 - Returns the - PlaybackState.- See also - playing- Access functions:
 - property playingᅟ: bool¶
 - This property holds Whether the media is playing.. - See also - Access functions:
- Signal - playingChanged()
 
 - property 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 - seekableproperty is true, this property can be set to milliseconds.- Access functions:
 - property 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 - QMediaPlayerobject, use the- seekableChangedsignal to monitor changes.- Access functions:
- Signal - seekableChanged()
 
 - 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 - Access functions:
- Signal - sourceChanged()
 
 - property subtitleTracksᅟ: list of QMediaMetaData¶
 - Lists the set of available subtitle tracks inside the media. - The - QMediaMetaDatareturned describes the properties of individual tracks.- Access functions:
- Signal - tracksChanged()
 
 - 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 - nullptrwill disable video output.- Access functions:
 - property videoTracksᅟ: list of QMediaMetaData¶
 - Lists the set of available video tracks inside the media. - The - QMediaMetaDatareturned describes the properties of individual tracks.- Access functions:
- Signal - tracksChanged()
 
 - Constructs a - QMediaPlayerinstance as a child of- parent.- activeAudioTrack()¶
- Return type:
- int 
 - See also 
 - Getter of property - activeAudioTrackᅟ.- activeSubtitleTrack()¶
- Return type:
- int 
 - See also 
 - Getter of property - activeSubtitleTrackᅟ.- activeTracksChanged()¶
 - Notification signal of property - activeAudioTrackᅟ.- activeVideoTrack()¶
- Return type:
- int 
 - See also 
 - Getter of property - activeVideoTrackᅟ.- audioBufferOutput()¶
- Return type:
 - See also 
 - Getter of property - audioBufferOutputᅟ.- audioBufferOutputChanged()¶
 - Notification signal of property - audioBufferOutputᅟ.- audioOutput()¶
- Return type:
 - See also 
 - Getter of property - audioOutputᅟ.- audioOutputChanged()¶
 - Notification signal of property - audioOutputᅟ.- audioTracks()¶
- Return type:
- .list of QMediaMetaData 
 
 - Getter of property - audioTracksᅟ.- 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ᅟ.- bufferProgressChanged(progress)¶
- Parameters:
- progress – float 
 
 - Signals the amount of the local buffer - filledas a number between 0 and 1.- Notification signal of property - bufferProgressᅟ.- bufferedTimeRange()¶
- Return type:
 
 - Returns a - QMediaTimeRangedescribing the currently buffered data.- When streaming media from a remote source, different parts of the media file can be available locally. The returned - QMediaTimeRangeobject describes the time ranges that are buffered and available for immediate playback.- See also - 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ᅟ.- durationChanged(duration)¶
- Parameters:
- duration – int 
 
 - Signals the duration of the content has changed to - duration, expressed in milliseconds.- Notification signal of property - durationᅟ.- Returns the current error state. - Getter of property - errorᅟ.- errorChanged()¶
 - Notification signal of property - errorᅟ.- Signals that an - errorcondition has occurred, with- errorStringcontaining a description of the error.- See also - errorString()¶
- Return type:
- str 
 
 - Getter of property - errorStringᅟ.- hasAudio()¶
- Return type:
- bool 
 
 - Getter of property - hasAudioᅟ.- hasAudioChanged(available)¶
- Parameters:
- available – bool 
 
 - Signals the availability of audio content has changed to - available.- Notification signal of property - hasAudioᅟ.- hasVideo()¶
- Return type:
- bool 
 
 - Getter of property - hasVideoᅟ.- hasVideoChanged(videoAvailable)¶
- Parameters:
- videoAvailable – bool 
 
 - Signals the availability of visual content has changed to - videoAvailable.- Notification signal of property - hasVideoᅟ.- isAvailable()¶
- Return type:
- bool 
 
 - Returns true if the media player is supported on this platform. - isPlaying()¶
- Return type:
- bool 
 
 - Getter of property - playingᅟ.- 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 - Getter of property - seekableᅟ.- loops()¶
- Return type:
- int 
 - See also 
 - Getter of property - loopsᅟ.- loopsChanged()¶
 - Notification signal of property - loopsᅟ.- mediaStatus()¶
- Return type:
 
 - Getter of property - mediaStatusᅟ.- mediaStatusChanged(status)¶
- Parameters:
- status – - MediaStatus
 
 - Signals that the - statusof the current media has changed.- See also - Notification signal of property - mediaStatusᅟ.- metaData()¶
- Return type:
 
 - Getter of property - metaDataᅟ.- metaDataChanged()¶
 - Notification signal of property - metaDataᅟ.- pause()¶
 - Pause playing the current source. - play()¶
 - Start or resume playing the current source. - playbackRate()¶
- Return type:
- float 
 
 - Returns the current playback rate. - See also - Getter of property - playbackRateᅟ.- playbackRateChanged(rate)¶
- Parameters:
- rate – float 
 
 - Signals the - playbackRatehas changed to- rate.- Notification signal of property - playbackRateᅟ.- playbackState()¶
- Return type:
 
 - Getter of property - playbackStateᅟ.- playbackStateChanged(newState)¶
- Parameters:
- newState – - PlaybackState
 
 - Notification signal of property - playbackStateᅟ.- playingChanged(playing)¶
- Parameters:
- playing – bool 
 
 - Notification signal of property - playingᅟ.- 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 - Getter of property - positionᅟ.- positionChanged(position)¶
- Parameters:
- position – int 
 
 - Signals the position of the content has changed to - position, expressed in milliseconds.- Notification signal of property - positionᅟ.- seekableChanged(seekable)¶
- Parameters:
- seekable – bool 
 
 - Signals the - seekablestatus of the player object has changed.- Notification signal of property - seekableᅟ.- setActiveAudioTrack(index)¶
- Parameters:
- index – int 
 - See also 
 - Setter of property - activeAudioTrackᅟ.- setActiveSubtitleTrack(index)¶
- Parameters:
- index – int 
 - See also 
 - Setter of property - activeSubtitleTrackᅟ.- setActiveVideoTrack(index)¶
- Parameters:
- index – int 
 - See also 
 - Setter of property - activeVideoTrackᅟ.- setAudioBufferOutput(output)¶
- Parameters:
- output – - QAudioBufferOutput
 - See also 
 - Setter of property - audioBufferOutputᅟ.- setAudioOutput(output)¶
- Parameters:
- output – - QAudioOutput
 - See also 
 - Setter of property - audioOutputᅟ.- Setter of property - loopsᅟ.- setPlaybackRate(rate)¶
- Parameters:
- rate – float 
 - See also 
 - Setter of property - playbackRateᅟ.- setPosition(position)¶
- Parameters:
- position – int 
 - See also 
 - Setter of property - positionᅟ.- 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.- Note - FFmpeg, used by the FFmpeg media backend, restricts use of nested protocols for security reasons. In controlled environments where all inputs are trusted, the list of approved protocols can be overridden using the QT_FFMPEG_PROTOCOL_WHITELIST environment variable. This environment variable is Qt’s private API and can change between patch releases without notice. - See also - Setter of property - sourceᅟ.- Sets the current source - device.- The media data will be read from - device. The- sourceUrlcan be provided to resolve additional information about the media, mime type etc. The- devicemust be open and readable.- For macOS the - deviceshould 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 - Setter of property - videoOutputᅟ.- setVideoSink(sink)¶
- Parameters:
- sink – - QVideoSink
 
 - Sets - sinkto be the- QVideoSinkinstance to retrieve video data.- See also - source()¶
- Return type:
 - See also 
 - Getter of property - sourceᅟ.- Signals that the media source has been changed to - media.- Notification signal of property - sourceᅟ.- Returns the stream source of media data. - This is only valid if a stream was passed to - setSource().- See also - stop()¶
 - Stop playing, and reset the play position to the beginning. - subtitleTracks()¶
- Return type:
- .list of QMediaMetaData 
 
 - Getter of property - subtitleTracksᅟ.- tracksChanged()¶
 - Notification signal of property - audioTracksᅟ.- videoOutput()¶
- Return type:
 - See also 
 - Getter of property - videoOutputᅟ.- videoOutputChanged()¶
 - Notification signal of property - videoOutputᅟ.- videoSink()¶
- Return type:
 
 - Returns the - QVideoSinkinstance.- See also - videoTracks()¶
- Return type:
- .list of QMediaMetaData 
 
 - Getter of property - videoTracksᅟ.