首页 > 解决方案 > 存储 MediaPlayer 的内容 (QML/Qt)

问题描述

我正在使用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"
    }
}

标签: androidc++qtqml

解决方案


像这样的东西应该工作。有关更多属性,请查看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
                }
            }

        }

推荐阅读