QMediaPlayer¶
The
QMediaPlayer
class allows the playing of a media source. More…
Synopsis¶
Functions¶
def
audioRole
()def
bufferStatus
()def
currentMedia
()def
currentNetworkConfiguration
()def
customAudioRole
()def
duration
()def
error
()def
errorString
()def
isAudioAvailable
()def
isMuted
()def
isSeekable
()def
isVideoAvailable
()def
media
()def
mediaStatus
()def
mediaStream
()def
playbackRate
()def
playlist
()def
position
()def
setAudioRole
(audioRole)def
setCustomAudioRole
(audioRole)def
setVideoOutput
(arg__1)def
setVideoOutput
(arg__1)def
setVideoOutput
(surface)def
state
()def
supportedAudioRoles
()def
supportedCustomAudioRoles
()def
volume
()
Slots¶
def
pause
()def
play
()def
setMedia
(media[, stream=None])def
setMuted
(muted)def
setNetworkConfigurations
(configurations)def
setPlaybackRate
(rate)def
setPlaylist
(playlist)def
setPosition
(position)def
setVolume
(volume)def
stop
()
Signals¶
def
audioAvailableChanged
(available)def
audioRoleChanged
(role)def
bufferStatusChanged
(percentFilled)def
currentMediaChanged
(media)def
customAudioRoleChanged
(role)def
durationChanged
(duration)def
error
(error)def
mediaChanged
(media)def
mediaStatusChanged
(status)def
mutedChanged
(muted)def
networkConfigurationChanged
(configuration)def
playbackRateChanged
(rate)def
positionChanged
(position)def
seekableChanged
(seekable)def
stateChanged
(newState)def
videoAvailableChanged
(videoAvailable)def
volumeChanged
(volume)
Static functions¶
def
hasSupport
(mimeType[, codecs=list()[, flags=QMediaPlayer.Flags()]])def
supportedMimeTypes
([flags=QMediaPlayer.Flags()])
Detailed Description¶
The
QMediaPlayer
class is a high level media playback class. It can be used to playback such content as songs, movies and internet radio. The content to playback is specified as aQMediaContent
object, which can be thought of as a main or canonical URL with additional information attached. When provided with aQMediaContent
playback may be able to commence.player = new QMediaPlayer; connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); player->setVolume(50); player->play();
QVideoWidget
can be used withQMediaPlayer
for video rendering andQMediaPlaylist
for accessing playlist functionality.playlist = new QMediaPlaylist; playlist->addMedia(QUrl("http://example.com/movie1.mp4")); playlist->addMedia(QUrl("http://example.com/movie2.mp4")); playlist->addMedia(QUrl("http://example.com/movie3.mp4")); playlist->setCurrentIndex(1); player = new QMediaPlayer; player->setPlaylist(playlist); videoWidget = new QVideoWidget; player->setVideoOutput(videoWidget); videoWidget->show(); player->play();Since
QMediaPlayer
is aQMediaObject
, you can use several of theQMediaObject
functions for things like:
Accessing the currently playing media’s metadata (
metaData()
and predefined meta-data keys )Checking to see if the media playback service is currently available (
availability()
)
-
class
QMediaPlayer
([parent=None[, flags=QMediaPlayer.Flags()]])¶ - param parent
QObject
- param flags
Flags
Construct a
QMediaPlayer
instance parented toparent
and withflags
.
-
PySide2.QtMultimedia.QMediaPlayer.
State
¶ 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.
-
PySide2.QtMultimedia.QMediaPlayer.
MediaStatus
¶ Defines the status of a media player’s current media.
Constant
Description
QMediaPlayer.UnknownMediaStatus
The status of the media cannot be determined.
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
orPausedState
.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
orPausedState
.QMediaPlayer.BufferedMedia
The player has fully buffered the current media. The player is in the
PlayingState
orPausedState
.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
.
-
PySide2.QtMultimedia.QMediaPlayer.
Flag
¶ Constant
Description
QMediaPlayer.LowLatency
The player is expected to be used with simple audio formats, but playback should start without significant delay. Such playback service can be used for beeps, ringtones, etc.
QMediaPlayer.StreamPlayback
The player is expected to play
QIODevice
based streams. If passed toQMediaPlayer
constructor, the service supporting streams playback will be chosen.QMediaPlayer.VideoSurface
The player is expected to be able to render to a
QAbstractVideoSurface
output
.
-
PySide2.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.
QMediaPlayer.ServiceMissingError
A valid playback service was not found, playback cannot proceed.
-
PySide2.QtMultimedia.QMediaPlayer.
audioAvailableChanged
(available)¶ - Parameters
available –
bool
-
PySide2.QtMultimedia.QMediaPlayer.
audioRole
()¶ - Return type
Role
See also
-
PySide2.QtMultimedia.QMediaPlayer.
audioRoleChanged
(role)¶ - Parameters
role –
Role
-
PySide2.QtMultimedia.QMediaPlayer.
bufferStatus
()¶ - Return type
int
-
PySide2.QtMultimedia.QMediaPlayer.
bufferStatusChanged
(percentFilled)¶ - Parameters
percentFilled –
int
-
PySide2.QtMultimedia.QMediaPlayer.
currentMedia
()¶ - Return type
-
PySide2.QtMultimedia.QMediaPlayer.
currentMediaChanged
(media)¶ - Parameters
media –
QMediaContent
-
PySide2.QtMultimedia.QMediaPlayer.
currentNetworkConfiguration
()¶ - Return type
QNetworkConfiguration
Returns the current network access point in use. If a default contructed
QNetworkConfiguration
is returned this feature is not available or that none of the current supplied configurations are in use.
-
PySide2.QtMultimedia.QMediaPlayer.
customAudioRole
()¶ - Return type
unicode
See also
-
PySide2.QtMultimedia.QMediaPlayer.
customAudioRoleChanged
(role)¶ - Parameters
role – unicode
-
PySide2.QtMultimedia.QMediaPlayer.
duration
()¶ - Return type
qint64
-
PySide2.QtMultimedia.QMediaPlayer.
durationChanged
(duration)¶ - Parameters
duration –
qint64
-
PySide2.QtMultimedia.QMediaPlayer.
error
(error) - Parameters
error –
Error
-
PySide2.QtMultimedia.QMediaPlayer.
errorString
()¶ - Return type
unicode
-
static
PySide2.QtMultimedia.QMediaPlayer.
hasSupport
(mimeType[, codecs=list()[, flags=QMediaPlayer.Flags()]])¶ - Parameters
mimeType – unicode
codecs – list of strings
flags –
Flags
- Return type
SupportEstimate
Returns the level of support a media player has for a
mimeType
and a set ofcodecs
.The
flags
argument allows additional requirements such as performance indicators to be specified.
-
PySide2.QtMultimedia.QMediaPlayer.
isAudioAvailable
()¶ - Return type
bool
-
PySide2.QtMultimedia.QMediaPlayer.
isMuted
()¶ - Return type
bool
-
PySide2.QtMultimedia.QMediaPlayer.
isSeekable
()¶ - Return type
bool
-
PySide2.QtMultimedia.QMediaPlayer.
isVideoAvailable
()¶ - Return type
bool
-
PySide2.QtMultimedia.QMediaPlayer.
media
()¶ - Return type
See also
-
PySide2.QtMultimedia.QMediaPlayer.
mediaChanged
(media)¶ - Parameters
media –
QMediaContent
-
PySide2.QtMultimedia.QMediaPlayer.
mediaStatus
()¶ - Return type
-
PySide2.QtMultimedia.QMediaPlayer.
mediaStatusChanged
(status)¶ - Parameters
status –
MediaStatus
-
PySide2.QtMultimedia.QMediaPlayer.
mediaStream
()¶ - Return type
QIODevice
Returns the stream source of media data.
This is only valid if a stream was passed to
setMedia()
.See also
-
PySide2.QtMultimedia.QMediaPlayer.
mutedChanged
(muted)¶ - Parameters
muted –
bool
-
PySide2.QtMultimedia.QMediaPlayer.
networkConfigurationChanged
(configuration)¶ - Parameters
configuration –
QNetworkConfiguration
-
PySide2.QtMultimedia.QMediaPlayer.
pause
()¶ Pause playing the current source.
-
PySide2.QtMultimedia.QMediaPlayer.
play
()¶ Start or resume playing the current source.
-
PySide2.QtMultimedia.QMediaPlayer.
playbackRate
()¶ - Return type
qreal
See also
-
PySide2.QtMultimedia.QMediaPlayer.
playbackRateChanged
(rate)¶ - Parameters
rate –
qreal
-
PySide2.QtMultimedia.QMediaPlayer.
playlist
()¶ - Return type
See also
-
PySide2.QtMultimedia.QMediaPlayer.
position
()¶ - Return type
qint64
See also
-
PySide2.QtMultimedia.QMediaPlayer.
positionChanged
(position)¶ - Parameters
position –
qint64
-
PySide2.QtMultimedia.QMediaPlayer.
seekableChanged
(seekable)¶ - Parameters
seekable –
bool
-
PySide2.QtMultimedia.QMediaPlayer.
setAudioRole
(audioRole)¶ - Parameters
audioRole –
Role
See also
-
PySide2.QtMultimedia.QMediaPlayer.
setCustomAudioRole
(audioRole)¶ - Parameters
audioRole – unicode
See also
-
PySide2.QtMultimedia.QMediaPlayer.
setMedia
(media[, stream=None])¶ - Parameters
media –
QMediaContent
stream –
QIODevice
Sets the current
media
source.If a
stream
is supplied; media data will be read from it instead of resolving the media source. In this case the media source may still be used to resolve additional information about the media such as mime type. Thestream
must be open and readable.Setting the media to a null
QMediaContent
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()
anderror()
signals to be notified when the media is loaded and when an error occurs during loading.See also
-
PySide2.QtMultimedia.QMediaPlayer.
setNetworkConfigurations
(configurations)¶ - Parameters
configurations –
Sets the network access points for remote media playback.
configurations
contains, in ascending preferential order, a list of configuration that can be used for network access.This will invalidate the choice of previous configurations.
-
PySide2.QtMultimedia.QMediaPlayer.
setPlaybackRate
(rate)¶ - Parameters
rate –
qreal
See also
-
PySide2.QtMultimedia.QMediaPlayer.
setPlaylist
(playlist)¶ - Parameters
playlist –
QMediaPlaylist
See also
-
PySide2.QtMultimedia.QMediaPlayer.
setPosition
(position)¶ - Parameters
position –
qint64
See also
-
PySide2.QtMultimedia.QMediaPlayer.
setVideoOutput
(surface)¶ - Parameters
surface –
QAbstractVideoSurface
Sets a video
surface
as the video output of a media player.If a video output has already been set on the media player the new surface will replace it.
-
PySide2.QtMultimedia.QMediaPlayer.
setVideoOutput
(arg__1) - Parameters
arg__1 –
QGraphicsVideoItem
Attach a
QGraphicsVideoItem
videooutput
to the media player.If the media player has already video output attached, it will be replaced with a new one.
-
PySide2.QtMultimedia.QMediaPlayer.
setVideoOutput
(arg__1) - Parameters
arg__1 –
QVideoWidget
Attach a
QVideoWidget
videooutput
to the media player.If the media player has already video output attached, it will be replaced with a new one.
-
PySide2.QtMultimedia.QMediaPlayer.
stop
()¶ Stop playing, and reset the play position to the beginning.
-
PySide2.QtMultimedia.QMediaPlayer.
supportedAudioRoles
()¶ - Return type
Returns a list of supported audio roles.
If setting the audio role is not supported, an empty list is returned.
See also
-
PySide2.QtMultimedia.QMediaPlayer.
supportedCustomAudioRoles
()¶ - Return type
list of strings
Returns a list of supported custom audio roles. An empty list may indicate that the supported custom audio roles aren’t known. The list may not be complete.
See also
-
static
PySide2.QtMultimedia.QMediaPlayer.
supportedMimeTypes
([flags=QMediaPlayer.Flags()])¶ - Parameters
flags –
Flags
- Return type
list of strings
Returns a list of MIME types supported by the media player.
The
flags
argument causes the resultant list to be restricted to MIME types which can be supported given additional requirements, such as performance indicators.This function may not return useful results on some platforms, and support for a specific file of a given mime type is not guaranteed even if the mime type is in general supported. In addition, in some cases this function will need to load all available media plugins and query them for their support, which may take some time.
-
PySide2.QtMultimedia.QMediaPlayer.
videoAvailableChanged
(videoAvailable)¶ - Parameters
videoAvailable –
bool
-
PySide2.QtMultimedia.QMediaPlayer.
volume
()¶ - Return type
int
See also
-
PySide2.QtMultimedia.QMediaPlayer.
volumeChanged
(volume)¶ - Parameters
volume –
int
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.