Start the trim video activity with an intent

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

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?

回答1:

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 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.



回答2:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!