QMediaPlayerclass allows the playing of a media source. 更多 …
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
(surface)
def
setVideoOutput
(surfaces)
def
state
()
def
supportedAudioRoles
()
def
supportedCustomAudioRoles
()
def
volume
()
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
()
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)
def
hasSupport
(mimeType[, codecs=list()[, flags=QMediaPlayer.Flags()]])
def
supportedMimeTypes
([flags=QMediaPlayer.Flags()])
QMediaPlayerclass 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对象,可以认为是附加了额外信息的主 URL 或典型 URL。当提供采用QMediaContent回放也许可以开始。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();
QVideoWidgetcan be used withQMediaPlayerfor video rendering andQMediaPlaylist为访问播放列表功能。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是QMediaObject,可以使用几个QMediaObject函数对于像这样的事情:
Accessing the currently playing media’s metadata (
metaData()and 预定义元数据键 )校验媒体回放服务目前是否可用 (
availability())
QMediaPlayer
(
[
parent=None
[
,
flags=QMediaPlayer.Flags()
]
]
)
¶
- param parent
QObject- param flags
标志
构造
QMediaPlayer
instance parented to
parent
和采用
flags
.
PySide2.QtMultimedia.QMediaPlayer.
State
¶
定义媒体播放器的当前状态。
|
常量 |
描述 |
|---|---|
|
QMediaPlayer.StoppedState |
媒体播放器未播放内容,回放将从当前轨道的起始开始。 |
|
QMediaPlayer.PlayingState |
媒体播放器目前正在播放内容。 |
|
QMediaPlayer.PausedState |
媒体播放器已暂停回放,当前轨道的回放将从播放器暂停位置处再继续。 |
PySide2.QtMultimedia.QMediaPlayer.
MediaStatus
¶
Defines the status of a media player’s current media.
|
常量 |
描述 |
|---|---|
|
QMediaPlayer.UnknownMediaStatus |
无法确定媒体状态。 |
|
QMediaPlayer.NoMedia |
当前没有媒体。播放器处于
|
|
QMediaPlayer.LoadingMedia |
当前正加载媒体。播放器可能处于任何状态。 |
|
QMediaPlayer.LoadedMedia |
The current media has been loaded. The player is in the
|
|
QMediaPlayer.StalledMedia |
Playback of the current media has stalled due to insufficient buffering or some other temporary interruption. The player is in the
|
|
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
|
|
QMediaPlayer.BufferedMedia |
The player has fully buffered the current media. The player is in the
|
|
QMediaPlayer.EndOfMedia |
回放已到达当前媒体结尾。播放器处于
|
|
QMediaPlayer.InvalidMedia |
当前媒体无法播放。播放器处于
|
PySide2.QtMultimedia.QMediaPlayer.
Flag
¶
|
常量 |
描述 |
|---|---|
|
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
|
|
QMediaPlayer.VideoSurface |
The player is expected to be able to render to a
|
PySide2.QtMultimedia.QMediaPlayer.
Error
¶
定义媒体播放器错误条件。
|
常量 |
描述 |
|---|---|
|
QMediaPlayer.NoError |
没有发生错误。 |
|
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 |
发生网络错误。 |
|
QMediaPlayer.AccessDeniedError |
没有适当权限来播放媒体资源。 |
|
QMediaPlayer.ServiceMissingError |
找不到有效回放服务,无法继续进行播放。开头 |
PySide2.QtMultimedia.QMediaPlayer.
audioAvailableChanged
(
available
)
¶
available
–
bool
PySide2.QtMultimedia.QMediaPlayer.
audioRole
(
)
¶
Role
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
audioRoleChanged
(
role
)
¶
role
–
Role
PySide2.QtMultimedia.QMediaPlayer.
bufferStatus
(
)
¶
int
PySide2.QtMultimedia.QMediaPlayer.
bufferStatusChanged
(
percentFilled
)
¶
percentFilled
–
int
PySide2.QtMultimedia.QMediaPlayer.
currentMedia
(
)
¶
PySide2.QtMultimedia.QMediaPlayer.
currentMediaChanged
(
media
)
¶
media
–
QMediaContent
PySide2.QtMultimedia.QMediaPlayer.
currentNetworkConfiguration
(
)
¶
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
(
)
¶
unicode
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
customAudioRoleChanged
(
role
)
¶
role – unicode
PySide2.QtMultimedia.QMediaPlayer.
duration
(
)
¶
qint64
PySide2.QtMultimedia.QMediaPlayer.
durationChanged
(
duration
)
¶
duration
–
qint64
PySide2.QtMultimedia.QMediaPlayer.
errorString
(
)
¶
unicode
PySide2.QtMultimedia.QMediaPlayer.
hasSupport
(
mimeType
[
,
codecs=list()
[
,
flags=QMediaPlayer.Flags()
]
]
)
¶
mimeType – unicode
codecs – 字符串列表
flags
–
标志
SupportEstimate
Returns the level of support a media player has for a
mimeType
and a set of
codecs
.
flags
argument allows additional requirements such as performance indicators to be specified.
PySide2.QtMultimedia.QMediaPlayer.
isAudioAvailable
(
)
¶
bool
PySide2.QtMultimedia.QMediaPlayer.
isMuted
(
)
¶
bool
PySide2.QtMultimedia.QMediaPlayer.
isSeekable
(
)
¶
bool
PySide2.QtMultimedia.QMediaPlayer.
isVideoAvailable
(
)
¶
bool
PySide2.QtMultimedia.QMediaPlayer.
media
(
)
¶
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
mediaChanged
(
media
)
¶
media
–
QMediaContent
PySide2.QtMultimedia.QMediaPlayer.
mediaStatus
(
)
¶
PySide2.QtMultimedia.QMediaPlayer.
mediaStatusChanged
(
status
)
¶
status
–
MediaStatus
PySide2.QtMultimedia.QMediaPlayer.
mediaStream
(
)
¶
QIODevice
Returns the stream source of media data.
This is only valid if a stream was passed to
setMedia()
.
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
mutedChanged
(
muted
)
¶
muted
–
bool
PySide2.QtMultimedia.QMediaPlayer.
networkConfigurationChanged
(
configuration
)
¶
configuration
–
QNetworkConfiguration
注意
此函数被弃用。
PySide2.QtMultimedia.QMediaPlayer.
pause
(
)
¶
暂停播放当前源。
PySide2.QtMultimedia.QMediaPlayer.
play
(
)
¶
开始 (或再继续) 播放当前源。
PySide2.QtMultimedia.QMediaPlayer.
playbackRate
(
)
¶
qreal
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
playbackRateChanged
(
rate
)
¶
rate
–
qreal
PySide2.QtMultimedia.QMediaPlayer.
playlist
(
)
¶
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
position
(
)
¶
qint64
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
positionChanged
(
position
)
¶
position
–
qint64
PySide2.QtMultimedia.QMediaPlayer.
seekableChanged
(
seekable
)
¶
seekable
–
bool
PySide2.QtMultimedia.QMediaPlayer.
setAudioRole
(
audioRole
)
¶
audioRole
–
Role
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setCustomAudioRole
(
audioRole
)
¶
audioRole – unicode
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setMedia
(
media
[
,
stream=None
]
)
¶
media
–
QMediaContent
stream
–
QIODevice
设置当前
media
源。
若
stream
is supplied; media data will be read from it instead of resolving the media source. In this case the url should be provided to resolve additional information about the media such as mime type. The
stream
must be open and readable. For macOS the
stream
should be also seekable.
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.
注意
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.
从 Qt 5.12.2 起,URL 方案
gst-pipeline
提供自定义管道为 GStreamer 后端。
player = new QMediaPlayer;
player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"));
player->play();
若
QAbstractVideoSurface
is used as the video output,
qtvideosink
can be used as a video sink element directly in the pipeline. After that the surface will receive the video frames in
present()
.
class Surface : public QAbstractVideoSurface
{
public:
Surface(QObject *p) : QAbstractVideoSurface(p) { }
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType) const override
{
// Make sure that the driver supports this pixel format.
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_YUYV;
}
// Video frames are handled here.
bool present(const QVideoFrame &) override { return true; }
};
player = new QMediaPlayer;
player->setVideoOutput(new Surface(player));
player->setMedia(QUrl("gst-pipeline: videotestsrc ! qtvideosink"));
player->play();
若
QVideoWidget
is used as the video output and the pipeline contains a video sink element named
qtvideosink
, current
QVideoWidget
will be used to render the video.
player = new QMediaPlayer;
videoWidget = new QVideoWidget;
videoWidget->show();
player->setVideoOutput(videoWidget);
player->setMedia(QUrl("gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\""));
player->play();
If the pipeline contains appsrc element, it will be used to push data from
stream
.
QImage img("images/qt-logo.png");
img = img.convertToFormat(QImage::Format_ARGB32);
QByteArray ba(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes());
QBuffer buffer(&ba);
buffer.open(QIODevice::ReadOnly);
player = new QMediaPlayer;
player->setMedia(QUrl("gst-pipeline: appsrc blocksize=4294967295 ! \
video/x-raw,format=BGRx,framerate=30/1,width=200,height=147 ! \
coloreffects preset=heat ! videoconvert ! video/x-raw,format=I420 ! jpegenc ! rtpjpegpay ! \
udpsink host=127.0.0.1 port=5000"), &buffer);
player->play();
QMediaPlayer *receiver = new QMediaPlayer;
videoWidget = new QVideoWidget;
receiver->setVideoOutput(videoWidget);
receiver->setMedia(QUrl("gst-pipeline: udpsrc port=5000 ! \
application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! \
xvimagesink name=qtvideosink"));
receiver->play();
// Content will be shown in this widget.
videoWidget->show();
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setNetworkConfigurations
(
configurations
)
¶
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
)
¶
rate
–
qreal
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setPlaylist
(
playlist
)
¶
playlist
–
QMediaPlaylist
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setPosition
(
position
)
¶
position
–
qint64
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
setVideoOutput
(
surface
)
¶
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
(
surfaces
)
¶
surfaces –
PySide2.QtMultimedia.QMediaPlayer.
stop
(
)
¶
停止播放,然后将播放位置重置到起始。
PySide2.QtMultimedia.QMediaPlayer.
supportedAudioRoles
(
)
¶
返回支持的音频角色列表。
If setting the audio role is not supported, an empty list is returned.
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
supportedCustomAudioRoles
(
)
¶
字符串列表
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.
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
supportedMimeTypes
(
[
flags=QMediaPlayer.Flags()
]
)
¶
flags
–
标志
字符串列表
Returns a list of MIME types supported by the media player.
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
)
¶
videoAvailable
–
bool
PySide2.QtMultimedia.QMediaPlayer.
volume
(
)
¶
int
另请参阅
PySide2.QtMultimedia.QMediaPlayer.
volumeChanged
(
volume
)
¶
volume
–
int