MediaPlayer QML 類

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

import 語句: import QtMultimedia
在 C++: QMediaPlayer

特性

信號

方法

詳細描述

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 [since 6.8]

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 > [read-only]

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 [since 6.7]

This property controls whether the media begins to play automatically after it gets loaded. Defaults to false .

該特性在 Qt 6.7 引入。

bufferProgress : real [read-only]

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 [read-only]

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 [read-only]

This property holds the error state of the audio. It can be one of the following.

描述
NoError 當前沒有錯誤。
ResourceError The audio cannot be played due to a problem allocating resources.
FormatError 音頻格式不支持。
NetworkError The audio cannot be played due to network issues.
AccessDeniedError The audio cannot be played due to insufficient permissions.

errorString : string [read-only]

This property holds a string describing the current error condition in more detail.

hasAudio : bool [read-only]

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

hasVideo : bool [read-only]

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

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 [read-only]

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

Property value 描述
NoMedia No media has been set.
LoadingMedia The media is currently being loaded.
LoadedMedia The media has been loaded.
BufferingMedia The media is buffering data.
StalledMedia Playback has been interrupted while the media is buffering data.
BufferedMedia The media has buffered data.
EndOfMedia The media has played to the end.
InvalidMedia The media cannot be played.

metaData : mediaMetaData [read-only]

返迴媒體播放器當前所用的媒體元數據。

元數據可以包含如視頻標題 (或其創建日期) 的信息。

注意: Windows 實現僅為位於本地文件係統中的媒體提供元數據。

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 [read-only]

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 [read-only, since 6.5]

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 [read-only]

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 > [read-only]

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 > [read-only]

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 .