【问题标题】:Set new path android设置新路径android
【发布时间】:2013-03-13 11:05:30
【问题描述】:

这是我的代码的一部分:

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);    
CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);     
mediaRecorder.setProfile(camcorderProfile_HQ);    
mediaRecorder.setOutputFile("/sdcard/Video.mp4");    
mediaRecorder.setMaxDuration(600000000); // Set max duration 60 sec.    
mediaRecorder.setMaxFileSize(500000000); // Set max file size 5M    

全班将视频从实时摄像头录制到 SD 卡。但由于我总是用相同的路径保存它,我录制的新视频会覆盖前一个视频。如何更改每次以新名称保存的路径或视频不会相互覆盖的方式?

【问题讨论】:

    标签: android path


    【解决方案1】:

    不要使用像 '/sdcard''/mnt/sdcard' 这样的硬核字符串。

    始终使用Environment.getExternalStorageDirectory()。每次使用以下函数获取新名称。

     private File getNextFileName() 
     {
        File file = new File(Environment.getExternalStorageDirectory(), "Video_" + System.currentTimeMillis() + ".mp4" );
        return file;
     }
    

    【讨论】:

      【解决方案2】:

      获取 System.nanoTime() 而不是 video.mp4 并将其插入到路径中。

      mediaRecorder.setOutputFile("/sdcard/" + System.nanoTime() + "_video.mp4");    
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-18
        • 2018-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多