- Qt 6.11
- Qt Multimedia
- QML Types
- Video
- Qt 6.11.2 Reference Documentation

# Video QML Type

A convenience type for showing a specified video. More...

Import Statement: | `import QtMultimedia`
Inherits: | Item

- List of all members, including inherited members

## Properties

- autoPlay : bool `(since 6.7)`
- bufferProgress : real
- duration : int
- endOfStreamPolicy : enumeration `(since 6.9)`
- error : enumeration
- errorString : string
- fillMode : enumeration
- hasAudio : bool
- hasVideo : bool
- loops : int
- metaData : mediaMetaData
- mirrored : int
- muted : bool
- orientation : int `(since 6.9)`
- playbackRate : real
- playbackState : enumeration
- position : int
- seekable : bool
- source : url
- volume : real

## Signals

- errorOccurred(error, errorString)
- paused()
- playing()
- stopped()

## Methods

- clearOutput() `(since 6.9)`
- pause()
- play()
- seek(offset)
- stop()

## Detailed Description

`Video` is a convenience type combining the functionality of a MediaPlayer and a 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 video.

Notice that because signals for the Keys 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.

See also MediaPlayer and VideoOutput.

## Property Documentation

### autoPlay : bool `[since 6.7]`

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

This property was introduced in 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.

### endOfStreamPolicy : enumeration `[since 6.9]`

This property specifies the policy to apply when the video stream ends.

The `endOfStreamPolicy` can be one of:

Constant | Description
--- | ---
`ClearOutput` | The video output is cleared.
`KeepLastFrame` | The video output continues displaying the last frame. Use the method clearOutput() to clear the output manually.

The default value is `VideoOutput.ClearOutput`.

This property was introduced in Qt 6.9.

### 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.

- VideoOutput.Stretch - the video is scaled to fit
- VideoOutput.PreserveAspectFit - the video is scaled uniformly to fit without cropping
- VideoOutput.PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary

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.

The default value is `1`. Setting this property to `0` has no effect.

### metaData : mediaMetaData

This property holds the meta data for the current media.

See MediaPlayer.metaData for details about each meta data key.

See also mediaMetaData.

### mirrored : int

Determines whether the displayed video is mirrored around its vertical axis. The mirroring is applied after orientation. The default value is `false`.

### muted : bool

This property holds whether the audio output is muted.

### orientation : int `[since 6.9]`

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. The orientation transformation is applied before mirrored.

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

The default value is `0`.

This property was introduced in Qt 6.9.

### 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.

- MediaPlayer.PlayingState - the media is playing
- MediaPlayer.PausedState - the media is paused
- MediaPlayer.StoppedState - the media is stopped

The default state is MediaPlayer.StoppedState.

### position : int

This property holds the current playback position in milliseconds.

### seekable : bool

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

If true, calling the seek() method or changing the position property will cause playback to seek to the new position.

### source : url

This property holds the source URL of the media.

### volume : real

This property holds the audio volume.

The volume is scaled linearly from `0.0` (silence) to `1.0` (full volume). Values outside this range will be clamped.

The default volume is `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 QtAudio::convertVolume() for more details.

## Signal Documentation

### errorOccurred(error, errorString)

This signal is emitted when an error has occurred. The errorString parameter may contain more detailed information about the error.

Note: The corresponding handler is `onErrorOccurred`.

### paused()

This signal is emitted when playback is paused.

Note: The corresponding handler is `onPaused`.

### playing()

This signal is emitted when playback is started or continued.

Note: The corresponding handler is `onPlaying`.

### stopped()

This signal is emitted when playback is stopped.

Note: The corresponding handler is `onStopped`.

## Method Documentation

### `[since 6.9]` clearOutput()

Clears the video output by removing the current video frame. This method is recommended when you need to remove the last video frame after the video stream ends with the endOfStreamPolicy Video property set to `KeepLastFrame`.

This method was introduced in Qt 6.9.

### pause()

Pauses playback of the media.

### play()

Starts playback of the media.

### seek(offset)

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

See also seekable and position.

### stop()

Stops playback of the media.