android - 存储 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"
}
}
解决方案
像这样的东西应该工作。有关更多属性,请查看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
}
}
}
推荐阅读
- r - 交叉验证的随机森林提供较低的准确度读数
- parallel-processing - MPI_Allreduce 未正确同步
- python - 如何参数化测试以在 pytest 中使用不同的夹具运行?
- google-bigquery - 如何水平连接来自不同表的列?
- reactjs - 如何在 Material-UI 菜单中使用自定义功能组件
- c# - 如何使用客户端-服务器架构有效地在游戏中发送对象
- reactjs - 多次调用 setState 时延迟
- php - 如何在 PHP 中显示本周的开始和结束日期?
- powershell - 是否可以使用 Invoke Webrequest 登录到使用 Azure AD B2C 身份验证的站点?
- c - 如何解决:传递“sutuntopla”的参数 1 使指针从整数变为没有强制转换警告?