Start the trim video activity with an intent - android

I can take a video with an intent now what are the details to create an intent to start the default video trimmer activity? And check if it present on the device?

This solution relies on a version of the AOSP Gallery2 package being installed on the device. You can do it like this:
// The Intent action is not yet published as a constant in the Intent class
// This one is served by the com.android.gallery3d.app.TrimVideo activity
// which relies on having the Gallery2 app or a compatible derivative installed
Intent trimVideoIntent = new Intent("com.android.camera.action.TRIM");
// The key for the extra has been discovered from com.android.gallery3d.app.PhotoPage.KEY_MEDIA_ITEM_PATH
trimVideoIntent.putExtra("media-item-path", getFilePathFromVideoURI(this, videoUri));
trimVideoIntent.setData(videoUri);
// Check if the device can handle the Intent
List<ResolveInfo> list = getPackageManager().queryIntentActivities(trimVideoIntent, 0);
if (null != list && list.size() > 0) {
startActivity(trimVideoIntent); // Fires TrimVideo activity into being active
}
The method getFilePathFromVideURI is based on the answer of this question: Get filename and path from URI from mediastore
public String getFilePathFromVideoURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Video.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
videoUri is an Uri pointing to something like this: content://media/external/video/media/43. You can gather one by issuing an ACTION_PICK Intent:
Intent pickVideoUriIntent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickVideoUriIntent, PICK_VIDEO_REQUEST);
In onActivityResult get the uri like so:
....
case PICK_VIDEO_REQUEST:
Uri videoUri = data.getData();
...
This solution works on my Galaxy Nexus with Android 4.3 Jelly Bean.
I am not sure if this is available on all Android devices.
A more reliable solution may be to fork the Gallery2 app and put the TrimVideo activity together with its dependencies into a library that can be delivered with your app.
Hope this helps anyway.

Try this may it helps
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 30000);
intent.putExtra("EXTRA_VIDEO_QUALITY", 0);
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);
This code works well on API >=2.2, but the duration limit does not work on API 2.1

Related

How to pick image or video on Android L?

I am using below code and it works fine below android 5. I am able to pick image or video from SD card.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("video/* image/*");
getActivity().startActivityForResult(photoPickerIntent, 1);
However on Android L it shows only videos.
tried searching but didn't find anything, any help will be appreciated.
hi #Mohit you can use this solution for image and video
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
getActivity().startActivityForResult(photoPickerIntent, 1);
for both image and video you can use setType(*/*);
here ACTION_GET_CONTENT is give only gallery selection while ACTION_PICK give many more options to pick image and video from different action, So as per #DipeshDhakal answer you should use only ACTION_GET_CONTENT.
and this is work on android L and api 10 also.
Use Intent.ACTION_GET_CONTENT
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("video/*, images/*");
startActivityForResult(photoPickerIntent, 1);
Was running into a similar issue. Code that worked on 5.0 and below started breaking on 5.1+, and only filtered by the first type passed in.
A co-worker came up the following, and I thought I'd share:
We were previously using the following intent:
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*,video/*");
and the following code to get the path from whatever the user selected, if anything:
public static String getFilePathFromURI(Uri imageUri, Activity context) {
String filePath = null;
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(imageUri,
filePathColumn, null, null, null);
if (cursor != null) {
try {
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
} finally {
cursor.close();
}
}
return filePath;
}
Now:
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
String[] mimetypes = {"image/*", "video/*"};
i.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
And to get the path, the getPath function found in this answer:
https://stackoverflow.com/a/20559175/434400

Playing audio from intent - ActivityNotFoundException

I am trying to play audio with the ACTION_VIEW intent, but regardless on what type of sound file (.mp3, .3gpp etc.) I always get the same error:
E/AndroidRuntime(3007): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/recording-23363382.3gpp typ=audio/3gpp }
My code:
Firstly here is where I launch the activity:
case R.id.largeThumbnailText:
media_column_index = mediacursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
mediacursor.moveToPosition(lastClicked);
mediaFileUri = Uri.parse(mediacursor.getString(media_column_index));
media_column_index = mediacursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE);
String mime = mediacursor.getString(media_column_index);
Intent playAudioIntent = new Intent();
playAudioIntent.setAction(Intent.ACTION_VIEW);
playAudioIntent.setDataAndType(mediaFileUri, mime);
startActivity(playAudioIntent);
break;
This is where I initiate the mediacursor:
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.MIME_TYPE };
mediacursor = getActivity().managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null,
null, null);
I do the same thing with video, so I don't see where the problem is. Might be worth mentioning that this is all done from within a fragment.
Forgot to mention I'm testing it on a HTC Sensation (android 2.3.4)
Appreciate any suggestions
Instead of your code
Intent playAudioIntent = new Intent();
playAudioIntent.setAction(Intent.ACTION_VIEW);
playAudioIntent.setDataAndType(mediaFileUri, mime);
startActivity(playAudioIntent);
Try something like this:
String movieurl = Environment.getExternalStorageDirectory() + "/Videos/Wildlife.wmv";
Intent playAudioIntent = new Intent(Intent.ACTION_VIEW);
playAudioIntent .setDataAndType(Uri.parse(movieurl), "video/*");
common error when setting wrong mime type in the intent take this example check if it is audio/mp3 to play mp3 audios
Uri data = Uri.parse("file:///sdcard/abc_xyz.mp3");
intent.setDataAndType(data,"audio/mp3");
startActivity(intent);

Playing a file in android mediaplayer

I want to play a video file recorded to be played in the mediaplayer of android.I want to call the media player through the intent and want to play the corresponding file of the passed uri.When I was trying I am getting an exception ActivityNotFound can anyone help me with a code.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURED) {
uriVideo = data.getData();
Toast.makeText(VedioRecording.this, uriVideo.getPath(),
Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
uriVideo = null;
Toast.makeText(VedioRecording.this, "Cancelled!", Toast.LENGTH_LONG)
.show();
}
if (requestCode == 2) {
selectedImageUri = data.getData();
// OI FILE Manager
filemanagerstring = selectedImageUri.getPath();
// MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
Intent intent1 = new Intent(android.provider.MediaStore.INTENT_ACTION_MUSIC_PLAYER).setData(selectedImageUri);
startActivityForResult(intent1, 3);
// videoviewPlay.setVideoURI(selectedImageUri);
// videoviewPlay.start();
}
if (requestCode == 3) {
}
}
private String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else {
return null;
}
}
}
this is my code i am geting activitynotfound exception
The most common scenario in which you get an ActivityNotFound exception is when you attempt to launch an Activity you have created without declaring it in the manifest.
Post your code that you use to launch the Activity to be sure. If you're trying to use an activity that should be provided by the framework externally from your application, you may just be setting up the Intent incorrectly
Update after code posted...
Your code seems to be using the intent action INTENT_ACTION_MUSIC_PLAYER and passing an image url as data (is it the path to an image or are your variables just misnamed?). You get an ActivityNotFoundException because the system doesn't have any intent receivers registered to handle that scenario. Also, if you look at the documentation for this constant, you'll see that they marked it deprecated at some point:
http://developer.android.com/reference/android/provider/MediaStore.html#INTENT_ACTION_MUSIC_PLAYER
I would normally use Intent.ACTION_VIEW and pass a mime type along with the data. Something like the following...
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(pathToVideoFile), "video/*");
startActivity(intent);
By passing the mime type of "video/*" to setDataAndType, you're being more specific with your request to the system.
If you want to query the system to find out if an Intent can be handled (meaning that the user's device running your code has an Activity registered that can handle the Intent), you can use the PackageManager.queryIntentActivities method:
queryIntentActivities
String extension = MimeTypeMap
.getFileExtensionFromUrl(selectedImagePath);
String mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
mediaIntent.setDataAndType(Uri.parse(selectedImagePath),
mimeType);
startActivity(mediaIntent);
this is the code that helped me

How can I use the camera in Droid X by Android application

In my two to three application I have to used camera activity from application. User taken the picture using camera and set that image on image View.
It works for all devices excepting Droid X. When the user takes the picture from Droid X mobile, application is forced close.
Here is my code for start camera activity:
public void startCameraActivity()
{
_path = Environment.getExternalStorageDirectory() + "/default.jpg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
_taken = true;
bita = BitmapFactory.decodeFile( _path);
imv.setImageBitmap(bita);
}
}
So what should I do to run camera activity successfully in Droid X? I wasn't able to find what the problem is.
The issue here is not a memory issue as Andro has commented on this, and other similar postings.
The issue is simply related to how the Droid X camera intent differs from other devices's.
In my case, I was receiving a NullPointerException when attempting to grab my specified URI that I passed to the camera as using "intent.putExtra( MediaStore.EXTRA_OUTPUT, imageUri );". Some device camera's do not take in this extra properly, and those cases need to be handled separately. (see accepted answer here).
Also in my case, with a Droid X running 2.3.3, the returned intent was null as well. My debugger would detach during the camera intent, indicating that there was something wrong outside of my control. The best I could do is follow the accepted answer here.
So I added a capture for when my desired imageUri is null, and since my returned intent was null, I added logic to grab the most recent photo taken (using this as an example).
if ( imageUri == null ) {
String[] projection = new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE };
final Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC" );
int column_index = cursor.getColumnIndexOrThrow( MediaStore.Images.Media.DATA );
cursor.moveToFirst();
fileUri = cursor.getString( column_index );
}
I hope this helps!

Android: No Application perform this action, why?

i want to browse all Audio files, but i am getting error like No application can perform this action.. this is my code for browse activity...
--> private static final int SELECT_MUSIC = 1;
String selectedImagePath;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button) findViewById(R.id.browse)).setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("music/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), SELECT_MUSIC);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_MUSIC) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
and i have also added permission to menifest file:: READ_PHONE_STATE
what's problem? any idea?
Thanks..
It means that No Application perform that action. Why? because None of the installed Applications perform that action. It has nothing to do with permissions.
You are probably running this on an emulator, which does not include any directory browser application.
The setType method is working with MIME type values only.
If you really just need the handling of music files "audio/" should be ok (as mentioned before). To be more flexible, you should try to detect the MIME code of the file.
Here is a code snippit how this may look like:
FileNameMap fileNameMap = URLConnection.getFileNameMap();
type = fileNameMap.getContentTypeFor("file://" + file.getPath());
Or (pre Gingerbread)
if (!file.getName().contains("."))
return null;
String ext = (String) file.getName().subSequence(
file.getName().lastIndexOf(".") + 1,
file.getName().length());
MimeTypeMap mimeMap = MimeTypeMap.getSingleton();
type = mimeMap.getMimeTypeFromExtension(ext);
I usually use the combination of both methods (use the pre Gingerbread version if the first approach fails).
You can use:
intent.setType("audio/*"); instead of intent.setType("music/*");
Then you can choose a track, not a playlist.
Could you find a way to choose a playlist?
I have the same problem, looking for a way to open and choose a playlist.

Categories

Resources