如何在android中重命名视频文件

时间:2013-06-26 13:10:29

标签: android file video android-videoview android-file

我尝试使用以下代码重命名视频文件:

File from = new File(outputFileName);
            File to = new File(mediaStorageDir,mediaFile);
            from.renameTo(to);

outputFileName = //mnt/sdcard/Movies/Your_voice/Your_voice.mp4

mediaFile = mediaStorageDir.getPath() + File.separator
                    + "Your_voice" +
                    timeStamp +
                    ".mp4";

mediaStorageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
                "Your_voice");

locat没有错误....但不执行重命名。

我认为这个问题是因为这个文件在videoview中播放所以在我添加videoView.setVideoPath("");的代码之前,但它没有帮助,我需要做什么?

向前谢谢......

1 个答案:

答案 0 :(得分:1)

在构造File对象时已经指定了mediaStorageDir

File to = new File(mediaStorageDir,mediaFile);

因此您应该从mediaStorageDir.getPath()中移除mediaFile,如下所示:

mediaFile = "Your_voice" + timeStamp + ".mp4";

您可能还应该从mediaStorageDir中删除Your_voice部分,只需使用:

mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);