【问题标题】:Name of video with current date/time?当前日期/时间的视频名称?
【发布时间】:2013-01-04 06:08:28
【问题描述】:

我是安卓新手。我有视频录制应用程序,我在其中捕获视频并存储它,我需要将视频的名称与当前日期和时间一起存储。那么有没有办法做同样的事情。直到我知道视频名称不采用数字格式值..

String mediaFile;
        File mediaStorageDir = new File(
                Environment.getExternalStorageDirectory(), "/VideoLogger");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("VideoLogger", "failed to create directory");
                return null;
            }
        }
        String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
                .format(new Date());
        if (!sufix.equals("movie")) {
            mediaFile = mediaStorageDir.getPath() + File.separator + "output_"
                    + timeStamp + "_" + sufix + ".txt";
        } else {
            mediaFile = mediaStorageDir.getPath() + File.separator + "output_"
                    + timeStamp + ".mp4";

        }

        return mediaFile;
    }
}

这是我用来命名我的视频文件的代码。

【问题讨论】:

    标签: android date time video-capture


    【解决方案1】:

    SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");//给你当前日期 currentDate = date.format(new Date());SimpleDateFormat time = new SimpleDateFormat("hh:mm a");//给你当前时间 currentTime = time.format(new Date());//这样存储 文件名 = currentDate +"-"+currentTime +".mp4";

    【讨论】:

      【解决方案2】:

      您可以使用此代码:

      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
                              String formattedDate = df.format(c.getTime());
      

      注意:您可以将 "yyyy-MM-dd HH.mm.ss" 更改为您想要的任何内容,例如 "yyyy_MM_dd_HH-mm-ss"

      编辑:以防万一你需要添加这个

      Calendar c = Calendar.getInstance();
      

      【讨论】:

      • 我需要将我的视频的名称存储在 sdcard 中,并且它不允许我播放该名称的视频。
      • 我没有在 textview 中设置值
      • 那么问题不在于名称,而在于您如何保存视频。
      【解决方案3】:

      使用此代码

      Date date=new Date();
      filename="/rec"+date.toString().replace(" ", "_").replace(":", "_")+".mp4";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-19
        • 1970-01-01
        • 1970-01-01
        • 2013-08-14
        • 2013-02-25
        • 2011-09-16
        • 2011-12-10
        相关资源
        最近更新 更多