将媒体回放添加到场景。 更多...
| import 语句: |
import QtMultimedia
|
| 在 C++: | QMediaPlayer |
(从 6.8 起)
(从 6.7 起)
(从 6.10 起)
(从 6.10 起)
(从 6.10 起)
(从 6.5 起)
Text { text: "Click Me!"; font.pointSize: 24; width: 150; height: 50; MediaPlayer { id: playMusic source: "music.wav" audioOutput: AudioOutput {} } MouseArea { anchors.fill: parent onPressed: { playMusic.play() } } }
You can use MediaPlayer together with a MultiMedia::AudioOutput to play audio content, or you can use it in conjunction with a Multimedia::VideoOutput for rendering video.
Item { MediaPlayer { id: mediaplayer source: "groovy_video.mp4" audioOutput: AudioOutput {} videoOutput: videoOutput } VideoOutput { id: videoOutput anchors.fill: parent } MouseArea { anchors.fill: parent onPressed: mediaplayer.play(); } }
另请参阅 AudioOutput and VideoOutput .
|
activeAudioTrack : int |
This property holds the track number of the currently active audio track. Set to
-1
to disable audio track.
默认特性值为
0
: the first audio track.
|
activeSubtitleTrack : int |
This property holds the track number of the currently active subtitle track. Set to
-1
to disable subtitle track.
默认特性值为
-1
: no subtitles active.
|
activeVideoTrack : int |
This property holds the track number of the currently active video audio track. Set to
-1
to disable video track.
默认特性值为
0
: the first video track.
|
audioBufferOutput
:
QAudioBufferOutput
|
This property holds the target audio buffer output.
Normal usage of MediaPlayer from QML should not require using this property.
该特性在 Qt 6.8 引入。
另请参阅 QMediaPlayer::audioBufferOutput ().
|
audioOutput : AudioOutput |
This property holds the target audio output. Accepts one AudioOutput 元素。
另请参阅 QMediaPlayer::setAudioOutput ().
|
audioTracks
:
list
<
mediaMetaData
>
|
This property holds a list of metadata. Each index refers to an audio track.
The metadata holds properties describing the individual tracks. For audio tracks the Language is usually the most important property.
另请参阅 mediaMetaData .
|
autoPlay
:
bool
|
This property controls whether the media begins to play automatically after it gets loaded. Defaults to
false
.
该特性在 Qt 6.7 引入。
|
bufferProgress
:
real
|
This property holds how much of the data buffer is currently filled, from
0.0
(空) 到
1.0
(完整)。
Playback can start or resume only when the buffer is entirely filled. When the buffer is filled,
MediaPlayer.Buffered
is true. When buffer progress is between
0.0
and
1.0
,
MediaPlayer.Buffering
被设为
true
.
值低于
1.0
implies that the property
MediaPlayer.StalledMedia
is
true
.
另请参阅 mediaStatus .
|
duration
:
int
|
This property holds the duration of the media in milliseconds.
If the media doesn't have a fixed duration (a live stream for example) this will be set to
0
.
|
error
:
enumeration
|
This property holds the error state of the audio. It can be one of the following.
| 常量 | 描述 |
|---|---|
MediaPlayer.NoError
|
没有出现错误。 |
MediaPlayer.ResourceError
|
无法解析媒体资源。 |
MediaPlayer.FormatError
|
不 (完全) 支持媒体资源格式。仍可能可以回放,但没有音频或视频组件。 |
MediaPlayer.NetworkError
|
发生网络错误。 |
MediaPlayer.AccessDeniedError
|
没有适当权限来播放媒体资源。 |
|
errorString
:
string
|
This property holds a string describing the current error condition in more detail.
|
hasAudio
:
bool
|
此特性保持媒体是否包含音频。
|
hasVideo
:
bool
|
此特性保持媒体是否包含视频。
|
loops : int |
Determines how often the media is played before the player stops. Set to MediaPlayer::Infinite to loop the current media file forever.
默认值为
1
。把此特性设为
0
不起作用。
|
mediaStatus
:
enumeration
|
This property holds the status of media loading. It can be one of the following:
| 常量 | 描述 |
|---|---|
MediaPlayer.NoMedia
|
The is no current media. The player is in the StoppedState. |
MediaPlayer.LoadingMedia
|
正加载当前媒体。播放器可能处于任何状态。 |
MediaPlayer.LoadedMedia
|
The current media has been loaded. The player is in the StoppedState. |
MediaPlayer.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. |
MediaPlayer.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. |
MediaPlayer.BufferedMedia
|
The player has fully buffered the current media. The player is in the PlayingState or PausedState. |
MediaPlayer.EndOfMedia
|
Playback has reached the end of the current media. The player is in the StoppedState. |
MediaPlayer.InvalidMedia
|
The current media cannot be played. The player is in the StoppedState. |
|
metaData
:
mediaMetaData
|
返回媒体播放器当前所用的媒体元数据。
元数据可以包含如视频标题 (或其创建日期) 的信息。
注意: Windows 实现仅为位于本地文件系统中的媒体提供元数据。
|
pitchCompensation
:
bool
|
This property holds whether pitch compensation is enabled.
此特性在 Qt 6.10 引入。
|
pitchCompensationAvailability
:
enumeration
|
Indicates the availability of pitch compensation of the
MediaPlayer
on the current backend. The enumeration
PitchCompensationAvailability
is scoped.
| 常量 | 描述 |
|---|---|
MediaPlayer.AlwaysOn
|
The media player is always performing pitch compensation. |
MediaPlayer.Available
|
The media player can be configured to use pitch compensation. If pitch compensation is available on the current platform, it will be enabled by default, but users can disable if needed. |
MediaPlayer.Unavailable
|
The media player is not able to perform pitch compensation on the current platform. |
此特性在 Qt 6.10 引入。
|
playbackOptions
:
playbackOptions
|
This property exposes the playbackOptions API that gives low-level control of media playback options. Although we strongly recommend to rely on the default settings of MediaPlayer , this API can be used to optimize media playback for specific use cases where the default options are not ideal.
Playback options take effect the next time MediaPlayer::source 改变。
此特性在 Qt 6.10 引入。
|
playbackRate : real |
This property holds the rate at which media is played at as a multiple of the normal rate.
更多信息,见 QMediaPlayer::playbackRate .
默认为
1.0
.
|
playbackState
:
enumeration
|
This property holds the state of media playback. It can be one of the following:
| Property value | 描述 |
|---|---|
| PlayingState | The media is currently playing. This indicates the same as the playing 特性。 |
| PausedState | Playback of the media has been suspended. |
| StoppedState | Playback of the media is yet to begin. |
|
playing
:
bool
|
Indicates whether the media is currently playing.
该特性在 Qt 6.5 引入。
另请参阅 playbackState .
|
位置 : int |
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.
若 seekable property is true, this property can be set to milliseconds.
|
seekable
:
bool
|
This property holds whether the position of the media can be changed.
|
source : url |
此特性保持媒体的源 URL (统一资源定位符)。
Item { MediaPlayer { id: mediaplayer source: "file:///test.mp4" videoOutput: videoOutput audioOutput: AudioOutput { } } VideoOutput { id: videoOutput anchors.fill: parent } MouseArea { id: playArea anchors.fill: parent onPressed: mediaplayer.play(); } }
另请参阅 QMediaPlayer::setSource ().
|
subtitleTracks
:
list
<
mediaMetaData
>
|
This property holds a list of metadata. Each index refers to a subtitle track.
The metadata holds properties describing the individual tracks. For subtitle tracks the Language is usually the most important property.
另请参阅 mediaMetaData .
|
videoOutput : VideoOutput |
This property holds the target video output. Accepts one VideoOutput 元素。
另请参阅 QMediaPlayer::setVideoOutput ().
|
videoTracks
:
list
<
mediaMetaData
>
|
This property holds a list of metadata. Each index refers to a video track.
The metadata holds properties describing the individual tracks.
另请参阅 mediaMetaData .
|
errorOccurred ( error , errorString ) |
此信号发射,当 error 出现。 errorString parameter may contain more detailed information about the error.
注意:
相应处理程序是
onErrorOccurred
.
另请参阅 QMediaPlayer::Error .
|
playbackStateChanged () |
此信号发射,当 playbackState 特性变更。
注意:
相应处理程序是
onPlaybackStateChanged
.
|
playingChanged () |
此信号发射,当 playing 特性改变。
注意:
相应处理程序是
onPlayingChanged
.
|
pause () |
暂停媒体回放。
设置
playbackState
property to PausedState, and changes
playing
to
false
.
|
play () |
Starts or resumes playback of the media.
设置
playbackState
property to PlayingState, and changes
playing
to
true
.
|
stop () |
停止媒体回放。
设置
playbackState
property to StoppedState, and changes
playing
to
false
.