【问题标题】:Storing the Content of MediaPlayer (QML/Qt)存储 MediaPlayer 的内容 (QML/Qt)
【发布时间】:2019-11-28 06:30:34
【问题描述】:

我正在使用Qt 开发电话应用程序。我在整个应用程序中使用了Qt C++ classes,但在某些时候我不得不在我的应用程序中将Qt QML Types 用于手机相机功能,现在我可以在MediaPlayer 上显示相机的内容。我想知道是否可以将此内容作为.mp4 文件或任何其他格式保存在手机存储中?

这是我在MediaPlayer 上显示此内容的一段代码:

import QtQuick 2.0
import QtMultimedia 5.0

Item {
    id: videoPreview
    property alias source : player.source
    signal closed

    MediaPlayer {

        id: player
        autoPlay: true

        onStatusChanged: {
            if (status == MediaPlayer.EndOfMedia)
                videoPreview.closed();
        }
    }

    VideoOutput {
        source: player
        anchors.fill : parent
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            videoPreview.closed();
        }
    }
}

我非常感谢任何提示或帮助,因为我是 QML Types 的初学者 :)。

这是我的主要 QML 文件。

import QtQuick 2.0
import QtMultimedia 5.4

Rectangle {
    id : cameraUI

    width: 640
    height: 480
    color: "black"
    state: "VideoCapture"

    states: [

        State {
            name: "VideoCapture"
            StateChangeScript {

                script: {
                    camera.position = Camera.FrontFace
                    camera.captureMode = Camera.CaptureVideo
                    camera.start()
                }
            }
        },
        State {
            name: "VideoPreview"
            StateChangeScript {
                script: {
                    camera.stop()
                }
            }
        }
    ]

    Camera {
        id: camera
        captureMode: Camera.CaptureVideo

        videoRecorder {

             resolution: "640x480"
             frameRate: 30
        }
    }

    VideoPreview {
        id : videoPreview
        anchors.fill : parent
        onClosed: cameraUI.state = "VideoCapture"
        visible: cameraUI.state == "VideoPreview"
        focus: visible

        //don't load recorded video if preview is invisible
        source: visible ? camera.videoRecorder.actualLocation : ""
    }

    VideoOutput {
        id: viewfinder
        visible: cameraUI.state == "VideoCapture"

        x: 0
        y: 0
       // width: parent.width
        width: parent.width - stillControls.buttonsPanelWidth
        height: parent.height

        source: camera
        autoOrientation: true
    }

    VideoCaptureControls {
        id: videoControls
        anchors.fill: parent
        camera: camera
        visible: cameraUI.state == "VideoCapture"
        onPreviewSelected: cameraUI.state = "VideoPreview"
    }
}

【问题讨论】:

    标签: android c++ qt qml


    【解决方案1】:

    这样的事情应该可以工作。有关更多属性,请查看 CameraRecorder 文档。

      Camera
            {
                id: camera
                captureMode: Camera.CaptureVideo
                videoRecorder.muted: true // set any property of recording.
            }
    
            VideoOutput 
            {
                source: camera
                width: parent.width*0.8
                height: parent.height*0.8
                autoOrientation: true
                anchors.centerIn: parent
    
                MouseArea
                {
                    property var myInt:0
                    anchors.fill: parent
                    onClicked:
                    {
                        camera.searchAndLock()
                        camera.videoRecorder.record()
                        if( myInt > 1 )
                        {
                            camera.videoRecorder.stop()
                            console.log(camera.videoRecorder.outputLocation)
                        }
                        myInt=myInt+1
                    }
                }
    
            }
    

    【讨论】:

    • 非常感谢您的回答。我需要为此创建另一个 QML 文件吗?
    • 这取决于你想做什么。在任何地方复制上面的代码应该可以工作。如果它解决了您的问题,您可以将答案标记为已接受吗?
    • 我已将它添加到我的主 QML 文件中,我在那里定义了相机和视频输出,但它似乎没有存储视频。第一次点击它开始录制的屏幕时,它会做什么。您能否详细解释一下,以便我可以正确修改代码? @Muhammet Ali Asan
    • 我将在我的问题部分向您提供我的主要 QML 文件,因为它太长而无法作为评论发布。请参考上面的代码。
    • 从控制台我检索到了这个 libFastPong.so: qml: file:///data/user/0/org.qtproject.example.FastPong/files/VID_00000048.mp4但我找不到这样的文件。你知道问题是什么吗?
    猜你喜欢
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多