Playing video clips

Playing video is as easy as playing audio; there's a Video type that supports playing the video and displaying the video on the display. Here's a video player that plays video when you click on it and pauses and restarts the playback when you press the Space bar:

import QtQuick 2.3
import QtMultimedia 5.0

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

The Keys type emits signals for the various keys that are pressed; here, we're tying the spacePressed signal to a script that pauses and plays a video.

Most of the properties of Video are the ...

Get Application Development with Qt Creator - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.