MediaPlayer QML 類

把媒體迴放添加到場景。 更多...

import 語句: import QtMultimedia 5.8

特性

信號

方法

詳細描述

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() }
    }
}
					

可以使用 MediaPlayer by itself to play audio content (like Audio ), 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.

可以檢索支持的值,采用 supportedAudioRoles() .

值可以是之一:

  • UnknownRole - the role is unknown or undefined.
  • MusicRole - 音樂。
  • VideoRole - soundtrack from a movie or a video.
  • VoiceCommunicationRole - voice communications, such as telephony.
  • AlarmRole - 鬧鍾。
  • NotificationRole - notification, such as an incoming e-mail or a chat request.
  • RingtoneRole - 鈴聲。
  • AccessibilityRole - for accessibility, such as with a screen reader.
  • SonificationRole - sonification, such as with user interface sounds.
  • GameRole- 遊戲音頻。

該 QML 特性在 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 ,值 autoLoad 將覆寫成 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 。值低於 1.0 隱含狀態 MediaPlayer.Stalled .

另請參閱 status .

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 當前沒有錯誤。
ResourceError The audio cannot be played due to a problem allocating resources.
FormatError 音頻格式不支持。
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

此特性保持媒體是否包含音頻。

hasVideo : bool

此特性保持媒體是否包含視頻。

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 以啓用無限循環。

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

此特性保持本機媒體對象。

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 組

metaData.title : variant

metaData.subTitle : variant

metaData.author : variant

metaData.comment : variant

metaData.description : variant

metaData.category : variant

metaData.genre : variant

metaData.year : variant

metaData.date : variant

metaData.userRating : variant

metaData.keywords : variant

metaData.language : variant

metaData.publisher : variant

metaData.copyright : variant

metaData.parentalRating : variant

metaData.ratingOrganization : variant

metaData.size : variant

metaData.mediaType : variant

metaData.audioBitRate : variant

metaData.audioCodec : variant

metaData.averageLevel : variant

metaData.channelCount : variant

metaData.peakValue : variant

metaData.sampleRate : variant

metaData.albumTitle : variant

metaData.albumArtist : variant

metaData.contributingArtist : variant

metaData.composer : variant

metaData.conductor : variant

metaData.lyrics : variant

metaData.mood : variant

metaData.trackNumber : variant

metaData.trackCount : variant

metaData.coverArtUrlSmall : variant

metaData.coverArtUrlLarge : variant

metaData.resolution : variant

metaData.pixelAspectRatio : variant

metaData.videoFrameRate : variant

metaData.videoBitRate : variant

metaData.videoCodec : variant

metaData.posterUrl : variant

metaData.chapterNumber : variant

metaData.director : variant

metaData.leadPerformer : variant

metaData.writer : variant

這些特性保持用於當前媒體的元數據。

  • metaData.title - 媒體標題。
  • metaData.subTitle - 媒體子標題。
  • metaData.author - 媒體作者。
  • metaData.comment - 關於媒體的用戶評論。
  • metaData.description - 媒體描述。
  • metaData.category - 媒體類彆。
  • metaData.genre - 媒體流派。
  • metaData.year - 媒體發行年份。
  • metaData.date - 媒體日期。
  • 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 - 媒體齣版商。
  • 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 - 媒體的大小 (以字節為單位)。
  • metaData.mediaType - 媒體類型。
  • 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 - 媒體歌詞。
  • 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 - 媒體作傢。

另請參閱 QMediaMetaData .

muted : bool

此特性保持音頻輸齣是否靜音。

默認為 false。

notifyInterval : int

The interval at which notifiable properties will update.

須申報特性是 position and bufferProgress .

The interval is expressed in milliseconds, the default value is 1000.

This QML property was introduced in Qt 5.9.

playbackRate : real

This property holds the rate at which audio is played at as a multiple of the normal rate.

默認為 1.0。

playbackState : enumeration

This property holds the state of media playback. It can be one of:

  • PlayingState - 媒體目前正播放。
  • PausedState - 媒體迴放已掛起。
  • StoppedState - 媒體迴放尚未開始。

playlist : Playlist

此特性保持用於媒體播放器的播放列錶。

設置播放列錶特性重置 source 成空字符串。

該 QML 特性在 Qt 5.6 引入。

position : int

此特性保持當前的迴放位置 (以毫秒為單位)。

要改變此位置,使用 seek() 方法。

另請參閱 seek() .

seekable : bool

This property holds whether position of the audio can be changed.

若 true,調用 seek() method will cause playback to seek to the new position.

source : url

此特性保持媒體的源 URL (統一資源定位符)。

Setting the source property clears the current playlist ,若有的話。

status : enumeration

This property holds the status of media loading. It can be one of:

  • NoMedia - 尚未設置媒體。
  • Loading - the media is currently being loaded.
  • Loaded - the media has been loaded.
  • Buffering - the media is buffering data.
  • Stalled - playback has been interrupted while the media is buffering data.
  • Buffered - the media has buffered data.
  • EndOfMedia - the media has played to the end.
  • InvalidMedia - the media cannot be played.
  • UnknownStatus - the status of the media is unknown.

volume : real

This property holds the audio volume of the media player.

按綫性比例縮放的音量是從 0.0 (無聲) 到 1.0 (全音量)。將鉗製超齣此範圍的值。

默認音量為 1.0 .

通常,UI 音量控件應按非綫性比例縮放。例如,使用對數比例縮放將産生感知響度的綫性變化,這通常是用戶期望的音量控製。見 QtMultimedia.convertVolume() 瞭解更多細節。


信號文檔編製

error ( error , errorString )

此信號發射,當 error 齣現。 errorString parameter may contain more detailed information about the error.

相應處理程序是 onError .

paused ()

此信號發射,當暫停迴放時。

相應處理程序是 onPaused .

playbackStateChanged ()

此信號被發射當 playbackState 特性變更。

相應處理程序是 onPlaybackStateChanged .

playing ()

This signal is emitted when playback is started or resumed.

相應處理程序是 onPlaying .

stopped ()

此信號發射,當停止迴放時。

相應處理程序是 onStopped .


方法文檔編製

pause ()

暫停媒體迴放。

設置 playbackState property to PausedState.

play ()

開始媒體迴放。

設置 playbackState property to PlayingState.

seek ( offset )

seekable property is true, seeks the current playback position to offset .

Seeking may be asynchronous, so the position property may not be updated immediately.

另請參閱 seekable and position .

stop ()

停止媒體迴放。

設置 playbackState 特性成 StoppedState。

list < int > supportedAudioRoles ()

返迴支持的音頻角色列錶。

若不支持設置的音頻角色,返迴空列錶。

This QML method was introduced in Qt 5.6.

另請參閱 audioRole .