首页 > 解决方案 > 如何使用 video 5.12 qt qml 播放视频?

问题描述

我想用播放按钮播放视频,暂停,在10秒内转发视频,然后使用qml返回视频,但我不知道如何。

像这样的东西:

import QtQuick 2.12

import QtQuick.Window 2.12

import QtMultimedia 5.12

import QtQuick.Controls 2.0

import QtQuick.Layouts 1.12

Window {
    visible: true
    width: 840
    height: 680
    title: qsTr("Hello World")

    ColumnLayout{
        Video {
            id: video
            width : 600
            height : 600
            source: "a.avi"

        }
        RowLayout{
            Button {
                width: 80
                height: 80
                text: "play"
                onClicked: {video.play()}
            }
            Button {
                width: 80
                height: 80
                text: "pause"
                onClicked: {video.pause()}
            }
            Button {
                width: 80
                height: 80
                text: "foward"
                onClicked: {video.foward()}
            }
            Button {
                width: 80
                height: 80
                text: "back"
                onClicked: {video.back()}
            }
        }
    }
}

标签: qtc++11qml

解决方案


问题是来源。您需要使用 URL 格式: source: "file:///home/user/videos/a.avi"

或者,您可以使用 QtResources 文件 ( ) 将视频嵌入到可执行文件中.qrc


推荐阅读