MediaPlayer QML 类

Adds media playback to a scene. 更多...

import 语句: import QtMultimedia
实例化: 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.

The default property value is 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.

The default property value is -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.

The default property value is 0 : the first video track.

audioOutput : AudioOutput

This property holds the target audio output. Accepts one AudioOutput 元素。

另请参阅 QMediaPlayer::setAudioOutput ().

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

[read-only] 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 0.1 , MediaPlayer.Buffering 被设为 true .

A value lower than 1.0 implies that the property MediaPlayer.StalledMedia is true .

另请参阅 mediaStatus .

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

[read-only] error : enumeration

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.

[read-only] errorString : string

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

[read-only] hasAudio : bool

此特性保持媒体是否包含音频。

[read-only] 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 不起作用。

[read-only] mediaStatus : enumeration

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.

[read-only] metaData : mediaMetaData

Returns meta data for the current media used by the media player.

Meta data can contain information such as the title of the video or its creation date.

注意: The Windows implementation provides metadata only for media located on the local file system.

playbackRate : real

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

默认为 1.0 .

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

[read-only, since 6.5] playing : bool

Indicates whether the media is currently playing.

This property was introduced in Qt 6.5.

另请参阅 playbackState .

position : 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.

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

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

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

方法文档编制

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 .