dislike_mfc 2023-02-07 00:13 采纳率: 0%
浏览 174
已结题

unity使用easyar录屏更换视频保存路径

当前默认是保存在Android/data/包名/files
又尝试更改路径到/storage/dmic
但是会报错(是因为这个路径算外部路径吗)
不知道怎么操作。希望是保存的录屏在系统相册视频中能够查看

  • 写回答

13条回答 默认 最新

  • 火星的猫FM 2023-02-09 22:29
    关注

    首先,您需要确保您的设备有拓展存储卡,并且您有权在其中创建文件。 具体的步骤如下:

    打开 Unity 的项目,并创建一个新的 C# 脚本,命名为“ScreenRecorder”。

    在 ScreenRecorder 脚本中,添加以下代码:

    using EasyAR;
    using System.IO;
    using UnityEngine;
    
    public class ScreenRecorder : MonoBehaviour
    {
        public string folderName = "EasyAR Screen Recordings";
        public string fileName = "EasyARScreenRecording";
        public int recordingWidth = 720;
        public int recordingHeight = 1280;
    
        private ScreenRecorderBase recorderBase;
        private string rootPath;
    
        private void Start()
        {
            rootPath = Path.Combine(Application.persistentDataPath, folderName);
            recorderBase = GetComponent<ScreenRecorderBase>();
            recorderBase.RecordingWidth = recordingWidth;
            recorderBase.RecordingHeight = recordingHeight;
        }
    
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                if (recorderBase.IsRecording)
                {
                    recorderBase.StopRecording();
                    string filePath = Path.Combine(rootPath, fileName + ".mp4");
                    Debug.Log("Screen recording saved to: " + filePath);
    
                    // add code here to copy the recording to a public folder
                    // ...
                }
                else
                {
                    recorderBase.StartRecording();
                    Debug.Log("Screen recording started");
                }
            }
        }
    }
    
    
    

    在新的脚本中,修改 rootPath 变量的值为所需的文件夹路径,例如:
    rootPath = Path.Combine("/storage/emulated/0/DCIM", folderName);

    4、在 Update 函数中,添加以下代码:

    if (recorderBase.IsRecording)
    {
        recorderBase.StopRecording();
        string filePath = Path.Combine(rootPath, fileName + ".mp4");
        Debug.Log("Screen recording saved to: " + filePath);
    
        // copy the recording to a public folder
        string publicFilePath = Path.Combine("/storage/emulated/0/DCIM/Camera", fileName + ".mp4");
        File.Copy(filePath, publicFilePath, true);
    
        // refresh the Android Gallery to show the newly added file
        AndroidJavaClass class
    
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 2月15日
  • 创建了问题 2月7日

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)