Video QML 类型

用于展示指定视频的方便类型。 更多...

import 语句: import QtMultimedia
继承:

Item

特性

信号

方法

详细描述

Video is a convenience type combining the functionality of a MediaPlayer VideoOutput into one. It provides simple video playback functionality without having to declare multiple types.

The following is sample code to implement video playback in a scene.

Video {
    id: video
    width : 800
    height : 600
    source: "video.avi"
    MouseArea {
        anchors.fill: parent
        onClicked: {
            video.play()
        }
    }
    focus: true
    Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
    Keys.onLeftPressed: video.position = video.position - 5000
    Keys.onRightPressed: video.position = video.position + 5000
}
					

The source file, video.avi , plays when you click the parent of MouseArea . The video plays in an area of 800 by 600 pixels, and its id property has the value 视频 .

Notice that because signals for the have been defined pressing the:

  • Spacebar toggles the pause button.
  • Left Arrow moves the current position in the video to 5 seconds previously.
  • Right Arrow advances the current position in the video by 5 seconds.

Video supports un-transformed, stretched, and uniformly scaled video presentation. For a description of stretched uniformly scaled presentation, see the fillMode property description.

另请参阅 MediaPlayer and VideoOutput .

特性文档编制

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

This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 (full).

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 video. It can be one of:

  • MediaPlayer . NoError - there is no current error.
  • MediaPlayer .ResourceError - the video cannot be played due to a problem allocating resources.
  • MediaPlayer .FormatError - the video format is not supported.
  • MediaPlayer .NetworkError - the video cannot be played due to network issues.
  • MediaPlayer .AccessDenied - the video cannot be played due to insufficient permissions.
  • MediaPlayer .ServiceMissing - the video 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.

fillMode : enumeration

Set this property to define how the video is scaled to fit the target area.

Because this type is for convenience in QML, it does not support enumerations directly, so enumerations from VideoOutput are used to access the available fill modes.

The default fill mode is preserveAspectFit.

hasAudio : bool

This property holds whether the current media has audio content.

hasVideo : bool

This property holds whether the current media has video content.

loops : int

Determines how often the media is played before stopping. Set to MediaPlayer .Infinite to loop the current media file forever.

默认值为 1 。把此特性设为 0 不起作用。

metaData : mediaMetaData

This property holds the meta data for the current media.

MediaPlayer.metaData for details about each meta data key.

另请参阅 mediaMetaData .

muted : bool

此特性保持音频输出是否静音。

orientation : int

This property determines the angle, in degrees, at which the displayed video is rotated clockwise in video coordinates, where the Y-axis points downwards on the display.

Only multiples of 90 degrees are supported, that is 0, 90, -90, 180, 270, etc., otherwise, the specified value is ignored.

默认值为 0 .

playbackRate : real

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

playbackState : enumeration

This read only property indicates the playback state of the media.

The default state is MediaPlayer .StoppedState.

位置 : int

此特性保持当前的回放位置 (以毫秒为单位)。

seekable : bool

This property holds whether the playback position of the video can be changed.

若 true,调用 seek () method or changing the 位置 property will cause playback to seek to the new position.

source : url

此特性保持媒体的源 URL (统一资源定位符)。

volume : real

此特性保持音频音量。

按线性比例缩放的音量是从 0.0 (无声) 到 1.0 (全音量)。将钳制超出此范围的值。

默认音量为 1.0 .

通常,UI 音量控件应按非线性比例缩放。例如,使用对数比例缩放将产生感知响度的线性变化,这通常是用户期望的音量控制。见 QtAudio::convertVolume () 了解更多细节。

信号文档编制

errorOccurred ( error , errorString )

此信号发射,当 error 出现。 errorString parameter may contain more detailed information about the error.

注意: 相应处理程序是 onErrorOccurred .

paused ()

此信号发射,当暂停回放时。

注意: 相应处理程序是 onPaused .

playing ()

This signal is emitted when playback is started or continued.

注意: 相应处理程序是 onPlaying .

stopped ()

此信号发射,当停止回放时。

注意: 相应处理程序是 onStopped .

方法文档编制

pause ()

暂停媒体回放。

play ()

开始媒体回放。

seek ( offset )

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

另请参阅 seekable and 位置 .

stop ()

停止媒体回放。

内容

  1. 特性

  2. 信号

  3. 方法

  4. 详细描述