idan
idan

Reputation: 2170

How to rename video file in android

I try to rename video file with this code:

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

when

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

and

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

and

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

no error in locat .... but not execute rename.

I thought this problem cause because this file play in videoview so before the code I add videoView.setVideoPath(""); but it dont help, what I need to do ???

thanks ahead...

Upvotes: 0

Views: 1280

Answers (1)

free3dom
free3dom

Reputation: 18978

You already specify the mediaStorageDir when constructing the File object:

File to = new File(mediaStorageDir,mediaFile);

so you should remove the mediaStorageDir.getPath() from mediaFile, as follows:

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

You should probably also remove the Your_voice part from the mediaStorageDir, just use:

mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

Upvotes: 1

Related Questions