W3cubDocs

/Qt

MediaPlayer QML Type

Adds media playback to a scene. More...

Import Statement: import QtMultimedia
Instantiates: QMediaPlayer

Properties

Signals

Methods

Detailed Description

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

See also AudioOutput and VideoOutput.

Property Documentation

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

See also QMediaPlayer::setAudioOutput().

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.

See also mediaMetaData.

bufferProgress : real

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

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 is set to true.

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

See also mediaStatus.

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.

error : enumeration

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

Value Description
NoError There is no current error.
ResourceError The audio cannot be played due to a problem allocating resources.
FormatError The audio format is not supported.
NetworkError The audio cannot be played due to network issues.
AccessDeniedError The audio cannot be played due to insufficient permissions.

errorString : string

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

hasAudio : bool

This property holds whether the media contains audio.

hasVideo : bool

This property holds whether the media contains video.

loops : int

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

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

mediaStatus : enumeration

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

Property value Description
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

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.

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

Defaults to 1.0.

playbackState : enumeration

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

Property value Description
PlayingState The media is currently playing.
PausedState Playback of the media has been suspended.
StoppedState Playback of the media is yet to begin.

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.

If the seekable property is true, this property can be set to milliseconds.

seekable : bool

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

source : url

This property holds the source URL of the media.

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

See also QMediaPlayer::setSource().

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.

See also mediaMetaData.

videoOutput : VideoOutput

This property holds the target video output. Accepts one VideoOutput elements.

See also QMediaPlayer::setVideoOutput().

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.

See also mediaMetaData.

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.

See also QMediaPlayer::Error.

playbackStateChanged()

This signal is emitted when the playbackState property is altered.

Note: The corresponding handler is onPlaybackStateChanged.

Method Documentation

pause()

Pauses playback of the media.

Sets the playbackState property to PausedState.

play()

Starts or resumes playback of the media.

Sets the playbackState property to PlayingState.

stop()

Stops playback of the media.

Sets the playbackState property to StoppedState.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qml-qtmultimedia-mediaplayer.html