How to rename video file in android - 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...

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);

Related

Deleting Video File in Android

I want to the delete the file after compression is done. I have used the code to delete the file. But when I check in the Gallery the video file is still there but it doesn't play shows error Media not Supported. Here is my code.
if (compressed) {
snackbar = TSnackbar
.make(coordinatorLayout,"Video Compressed Successfully",TSnackbar.LENGTH_SHORT);
snackbar.show();
//Delete File from Location.
File videoFile = new File(mediaFile.getPath());
if(videoFile.exists())
{
boolean del = videoFile.delete();
}
}
This is mediaFile
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
This is the storage directory
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
appName);
Try this
getContentResolver().delete(Uri.parse(mediafile.getPath()),null,null);

Captured video being saved to different folder than specified

I'm making an app that let's you either capture photo/video, or choose an existing photo/video before sending. I set up the directory to save the files in here:
String appName = Main.this.getString(R.string.app_name);
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_PICTURES), appName);
and I name the files here
File mediaFile;
Date now = new Date();
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(now);
String path = mediaStorageDir.getPath() + File.separator;
if(mediaType == MEDIA_TYPE_PHOTO){
mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
} else if(mediaType==MEDIA_TYPE_VIDEO){
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
}
So it's saving my pictures under /storage/emulated/0/pictures/(app name) with correct timestamped format. However, my videos are being saved to /storage/emulated/0/DCIM/100MEDIA and are just being named VIDEO0073, VIDEO00074, etc. I tried changing the directory name to MOVIES instead of PICTURES or DCIM, but there is no effect. I'm on an HTC One running Android 4.3
This is a bug that occurs on certain devices including the HTC One. If you include your code where you declare your video Intent I could more precisely answer the question, but basically, after you declare your Intent for the video (not image), get your Uri like so:
videoUri = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, new ContentValues());
In this case the video will be saved in the /storage/emulated/0/video folder instead of the pictures or dcim folders you mentioned above.

right path to a file in google glass memory

As a Google Glass developer, how can I reach the internal storage of the Glass?
I tried:
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "/DCIM/test.jpg");
but it doesn't work.
I want to be able to reach the photos and videos inside the device.
Thanks!
You should use (note the missing "/" at the begging):
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "DCIM/Camera/test.jpg");
An example path of a picture in the Glass storage is like:
/storage/emulated/0/DCIM/Camera/20140530_181813_833.jpg
you can get it with:
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "DCIM/Camera/20140530_181813_833.jpg");

Android - Get file with path

I would like to know how to get a file from its name.
I use the camera to take a photo. It saved the photo with this:
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
And now (after closing and opening again the app), I would like to get the file or Uri from the name of the picture (I saved it in a string (timeStamp)) to a preview.
Sorry for my english.

Android: How to access a file in the SD Card

I'm trying to access the image on the SD card using below code but I"m getting File not found exception. Can someone tell me a correct way to acess the file???
new File("/mnt/sdcard/splah2.jpg")
Try like this:
String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
new File(SD_CARD_PATH + "/" + "splah2.jpg");
Try running: new File(Environment.getExternalStorageDirectory() + "/splah2.jpg")
try this,
File f=new File("/sdcard/splah2.jpg");
The code below has worked for me.
String mRelativeFolderPath = "/DCIM/Camera/"; // i.e. SDCard/DCIM/Camera
String mBaseFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + mRelativeFolderPath;
String filePath = mBaseFolderPath + "test.jpg";
File handle = new File(filePath);
Shash
try
new File("/sdcard/splah2.jpg")
or
new File(Environment.getExternalStorageDirectory() + "/" + "splah2.jpg")
both are same if SD card is install because,
Environment.getExternalStorageDirectory() returns "/sdcard"

Categories

Resources