把媒体回放添加到场景。 更多...
import 语句: | import QtMultimedia 5.15 |
Text { text: "Click Me!"; font.pointSize: 24; width: 150; height: 50; MediaPlayer { id: playMusic source: "music.wav" } MouseArea { id: playArea anchors.fill: parent onPressed: { playMusic.play() } } }
You can use MediaPlayer by itself to play audio content (like 音频 ), or you can use it in conjunction with a VideoOutput for rendering video.
Item { MediaPlayer { id: mediaplayer source: "groovy_video.mp4" } VideoOutput { anchors.fill: parent source: mediaplayer } MouseArea { id: playArea anchors.fill: parent onPressed: mediaplayer.play(); } }
另请参阅 VideoOutput .
audioRole : enumeration |
This property holds the role of the audio stream. It can be set to specify the type of audio being played, allowing the system to make appropriate decisions when it comes to volume, routing or post-processing.
The audio role must be set before setting the source property.
Supported values can be retrieved with supportedAudioRoles() .
The value can be one of:
customAudioRole is cleared when this property is set to anything other than CustomRole.
该特性在 Qt 5.6 引入。
autoLoad : bool |
This property indicates if loading of media should begin immediately.
Defaults to true, if false media will not be loaded until playback is started.
autoPlay : bool |
This property controls whether the media will begin to play on start up.
默认为
false
。若设为
true
, the value of
autoLoad
will be overwritten to
true
.
availability : enumeration |
Returns the availability state of the media player.
This is one of:
值 | 描述 |
---|---|
Available | The media player is available to use. |
Busy | The media player is usually available, but some other process is utilizing the hardware necessary to play media. |
Unavailable | There are no supported media playback facilities. |
ResourceMissing | There is one or more resources missing, so the media player cannot be used. It may be possible to try again at a later time. |
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, in which case the status is
MediaPlayer.Buffered
or
MediaPlayer.Buffering
. A value lower than
1.0
implies that the status is
MediaPlayer.Stalled
.
另请参阅 status .
customAudioRole : string |
This property holds the role of the audio stream when the backend supports audio roles unknown to Qt. It can be set to specify the type of audio being played, allowing the system to make appropriate decisions when it comes to volume, routing or post-processing.
The audio role must be set before setting the source property.
audioRole is set to CustomRole when this property is set.
该特性在 Qt 5.11 引入。
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 0.
error : enumeration |
This property holds the error state of the audio. It can be one of:
值 | 描述 |
---|---|
NoError | There is no current error. |
ResourceError | The audio cannot be played due to a problem allocating resources. |
FormatError | The audio format is not supported. |
NetworkError | The audio cannot be played due to network issues. |
AccessDenied | The audio cannot be played due to insufficient permissions. |
ServiceMissing | The audio cannot be played because the media service could not be instantiated. |
errorString : string |
This property holds a string describing the current error condition in more detail.
hasAudio : bool |
This property holds whether the media contains audio.
hasVideo : bool |
This property holds whether the media contains video.
loops : int |
This property holds the number of times the media is played. A value of
0
or
1
means the media will be played only once; set to
MediaPlayer.Infinite
to enable infinite looping.
The value can be changed while the media is playing, in which case it will update the remaining loops to the new value.
默认为
1
.
mediaObject : variant |
This property holds the native media object.
It can be used to get a pointer to a QMediaPlayer object in order to integrate with C++ code.
QObject *qmlMediaPlayer; // The QML MediaPlayer object QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(qmlMediaPlayer->property("mediaObject"));
注意: This property is not accessible from QML.
metaData group |
---|
metaData.albumArtist : variant |
metaData.albumTitle : variant |
metaData.audioBitRate : variant |
metaData.audioCodec : variant |
: |
metaData.averageLevel : variant |
metaData.category : variant |
metaData.channelCount : variant |
metaData.chapterNumber : variant |
metaData.comment : variant |
metaData.composer : variant |
metaData.conductor : variant |
metaData.contributingArtist : variant |
metaData.copyright : variant |
metaData.coverArtUrlLarge : variant |
metaData.coverArtUrlSmall : variant |
metaData.date : variant |
metaData.description : variant |
metaData.director : variant |
metaData.genre : variant |
metaData.keywords : variant |
metaData.language : variant |
metaData.leadPerformer : variant |
metaData.lyrics : variant |
metaData.mediaType : variant |
metaData.mood : variant |
metaData.parentalRating : variant |
metaData.peakValue : variant |
metaData.pixelAspectRatio : variant |
metaData.posterUrl : variant |
metaData.publisher : variant |
metaData.ratingOrganization : variant |
metaData.resolution : variant |
metaData.sampleRate : variant |
metaData.size : variant |
metaData.subTitle : variant |
metaData.title : variant |
metaData.trackCount : variant |
metaData.trackNumber : variant |
metaData.userRating : variant |
metaData.videoBitRate : variant |
metaData.videoCodec : variant |
metaData.videoFrameRate : variant |
metaData.writer : variant |
metaData.year : variant |
These properties hold the meta data for the current media.
metaData.title
- the title of the media.
metaData.subTitle
- the sub-title of the media.
metaData.author
- the author of the media.
metaData.comment
- a user comment about the media.
metaData.description
- a description of the media.
metaData.category
- the category of the media.
metaData.genre
- the genre of the media.
metaData.year
- the year of release of the media.
metaData.date
- the date of the media.
metaData.userRating
- a user rating of the media in the range of 0 to 100.
metaData.keywords
- a list of keywords describing the media.
metaData.language
- the language of the media, as an ISO 639-2 code.
metaData.publisher
- the publisher of the media.
metaData.copyright
- the media's copyright notice.
metaData.parentalRating
- the parental rating of the media.
metaData.ratingOrganization
- the name of the rating organization responsible for the parental rating of the media.
metaData.size
- the size of the media in bytes.
metaData.mediaType
- the type of the media.
metaData.audioBitRate
- the bit rate of the media's audio stream in bits per second.
metaData.audioCodec
- the encoding of the media audio stream.
metaData.averageLevel
- the average volume level of the media.
metaData.channelCount
- the number of channels in the media's audio stream.
metaData.peakValue
- the peak volume of media's audio stream.
metaData.sampleRate
- the sample rate of the media's audio stream in hertz.
metaData.albumTitle
- the title of the album the media belongs to.
metaData.albumArtist
- the name of the principal artist of the album the media belongs to.
metaData.contributingArtist
- the names of artists contributing to the media.
metaData.composer
- the composer of the media.
metaData.conductor
- the conductor of the media.
metaData.lyrics
- the lyrics to the media.
metaData.mood
- the mood of the media.
metaData.trackNumber
- the track number of the media.
metaData.trackCount
- the number of tracks on the album containing the media.
metaData.coverArtUrlSmall
- the URL of a small cover art image.
metaData.coverArtUrlLarge
- the URL of a large cover art image.
metaData.resolution
- the dimension of an image or video.
metaData.pixelAspectRatio
- the pixel aspect ratio of an image or video.
metaData.videoFrameRate
- the frame rate of the media's video stream.
metaData.videoBitRate
- the bit rate of the media's video stream in bits per second.
metaData.videoCodec
- the encoding of the media's video stream.
metaData.posterUrl
- the URL of a poster image.
metaData.chapterNumber
- the chapter number of the media.
metaData.director
- the director of the media.
metaData.leadPerformer
- the lead performer in the media.
metaData.writer
- the writer of the media.
另请参阅 QMediaMetaData .
muted : bool |
This property holds whether the audio output is muted.
Defaults to false.
notifyInterval : int |
The interval at which notifiable properties will update.
The notifiable properties are position and bufferProgress .
The interval is expressed in milliseconds, the default value is 1000.
该特性在 Qt 5.9 引入。
playbackRate : real |
This property holds the rate at which audio is played at as a multiple of the normal rate.
Defaults to 1.0.
playbackState : enumeration |
This property holds the state of media playback. It can be one of:
playlist : Playlist |
This property holds the playlist used by the media player.
Setting the playlist property resets the source to an empty string.
该特性在 Qt 5.6 引入。
位置 : int |
This property holds the current playback position in milliseconds.
To change this position, use the seek() 方法。
另请参阅 seek() .
seekable : bool |
This property holds whether position of the audio can be changed.
If true, calling the seek() method will cause playback to seek to the new position.
source : url |
This property holds the source URL of the media.
Setting the source property clears the current playlist ,若有的话。
从 Qt 5.12.2 起,URL 方案
gst-pipeline
provides custom pipelines for the GStreamer backend.
If the pipeline contains a
qtvideosink
element, the current
VideoOutput
will be used for rendering video.
Item { MediaPlayer { id: mediaplayer source: "gst-pipeline: videotestsrc ! qtvideosink" } VideoOutput { anchors.fill: parent source: mediaplayer } MouseArea { id: playArea anchors.fill: parent onPressed: mediaplayer.play(); } }
另请参阅 QMediaPlayer::setMedia() .
status : enumeration |
This property holds the status of media loading. It can be one of:
videoOutput : url |
This property holds the target video output. Accepts one or an array of QAbstractVideoSurface or VideoOutput 元素。
Item { MediaPlayer { id: mediaplayer autoPlay: true source: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" videoOutput: [v1, v2] } VideoOutput { id: v1 anchors.fill: parent } Window { visible: true width: 480; height: 320 VideoOutput { id: v2 anchors.fill: parent } } }
该特性在 Qt 5.15 引入。
另请参阅 QMediaPlayer::setVideoOutput() .
volume : real |
This property holds the audio volume of the media player.
The volume is scaled linearly from
0.0
(无声) 到
1.0
(full volume). Values outside this range will be clamped.
默认音量为
1.0
.
UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale will produce linear changes in perceived loudness, which is what a user would normally expect from a volume control. See QtMultimedia.convertVolume() 了解更多细节。
此信号发射当 error has occurred. The errorString parameter may contain more detailed information about the error.
相应处理程序是
onError
.
注意:
相应处理程序是
onError
.
另请参阅 QMediaPlayer::Error .
This signal is emitted when playback is paused.
相应处理程序是
onPaused
.
注意:
相应处理程序是
onPaused
.
此信号发射当 playbackState property is altered.
相应处理程序是
onPlaybackStateChanged
.
注意:
相应处理程序是
onPlaybackStateChanged
.
This signal is emitted when playback is started or resumed.
相应处理程序是
onPlaying
.
注意:
相应处理程序是
onPlaying
.
This signal is emitted when playback is stopped.
相应处理程序是
onStopped
.
注意:
相应处理程序是
onStopped
.
Pauses playback of the media.
设置 playbackState property to PausedState.
Starts playback of the media.
设置 playbackState property to PlayingState.
若 seekable property is true, seeks the current playback position to offset .
Seeking may be asynchronous, so the position property may not be updated immediately.
Stops playback of the media.
设置 playbackState property to StoppedState.
返回支持的音频角色列表。
If setting the audio role is not supported, an empty list is returned.
This method was introduced in Qt 5.6.
另请参阅 audioRole .