I let the user record a video/audio by doing following:
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(videoIntent, VIDEO_REQUEST);
//pretty the same thing for audio
I'm not sure what to do in the onActivityResult() method to get the Uri of the recorded file and then convert it to an absolute path like /mnt/sdcard/DCIM/Camera/1231.avi
Any help is appreciated.
Try my program wherein you will get how to get the Path.The Link is as follows:-Imp Link.
Related
I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */
I have taken a video from camera which gets saved in camera/DCIM location on sdCard
Now my app takes the local path of the video and try playing the video using default video player with below code
private void playVideo(String path) {
Uri videoUri = Uri.parse(path);
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(videoUri, "video/*");
if (videoIntent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(videoIntent, null));
}
}
Now issue is the video doesn't play with a toast "Media view not found" on Mi devices + a few other.
But the same video plays through through selecting video from FileManager applications.
So I guess the issue is not with VideoPlayer. INSTEAD I think it's the issue with what mimeType is getting shared to the player. But thats just my assumption.
Anyone faced a similar issue, I need help as this issue is eating up my time.
Thanks
/storage/emulated/0/DCIM/Camera/VID_20160113_130138.mp4 is not a valid string representation of a Uri. A Uri needs a scheme.
Presumably, once upon a time, you had a File object for this. Use that, and Uri.fromFile(), instead of Uri.parse(). Or, use Uri.fromFile(new File(path)). This will give you the proper scheme setup.
I need to record Audio, And I would be pleased to use Built in Voice Recorder, but it would be nice to pass it parameters : Specific Path, Specific Quatlity, etc.
Is it posible?
I like this solution because code is very short:
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, AUDIO_RECORDING);
Here I have an example to copy file to specific location:
How can I specify the output file's folder when calling RECORD_SOUND_ACTION?
I guess it is not posible. If you need to customize it, you will need to develop your own activity. You can work with google Sample !
http://developer.android.com/guide/topics/media/audio-capture.html
How do you capture Video by calling the Android camera app using an intent in 4.3. I had it working in 4.2 and below. Even Google's sample is broken. Is this a bug? Or has Google changed how they return recorded video. Image capture still works.
I still get a RESULT_OK back but the intent data is null on MediaStore.ACTION_VIDEO_CAPTURE intents.
The problem
Yes, there is a bug starting with Android 4.3 release.
As the documentation says:
If EXTRA_OUTPUT is not present the video will be written to the
standard location for videos, and the Uri of that location will be
returned in the data field of the Uri.
What I have experienced is that the returned data field value is Null instead of containing the video file's Uri.
The solution
For now, is to pass MediaStore.EXTRA_OUTPUT to the Intent specifying the output location for the video file if the device's API Version is 18. This works as intended.
Since you were using the default gallery location for storing your videos, my guess is that you will want to keep it the same. So for this you need to set EXTRA_OUTPUT as follows.
Insert a new record into
MediaStore.Video.Media.EXTERNAL_CONTENT_URI:
Uri videoUri = context.getContentResolver().insert(EXTERNAL_CONTENT_URI, value);
Being value a ContentValues with display name, file type and file path to the new video file. E.g. :
ContentValues value = new ContentValues();
value.put(MediaStore.Video.Media.TITLE, "VideoTitle");
value.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
value.put(MediaStore.Video.Media.DATA, videoFilePath);
Pass the returned value, videoUri, as the EXTRA_OUPUT to the Intent.
I am using the following intent to invoke the camera and save the
recording as a specific name:
filepath = "/sdcard/testfolder/testvid.mp4";
File vidfile = new File(filepath);
Uri viduri = Uri.fromFile(vidfile);
Intent i = new
Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, viduri);
startActivity(i);
However the application keeps on crashing (The application has ....
stopped unexpectedly). But I noticed that the file has been saved with
the required name in the directory.
Any idea how can i resolve this? Basically I want to start the video
camera and save the subsequent recording in a specific directory and
name.
Thanks In Advance,
Perumal
Try with
startActivityForResult(i, 0);