启动修剪视频活动,意图 [英] Start the trim video activity with an intent

查看:181
本文介绍了启动修剪视频活动,意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以采取录像,意图现在什么都是细节,创建一个意图,启动默认的视频微调活动?并检查它是否$设备页码$ psent?

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?

推荐答案

该解决方案依赖于一个版本的AOSP库2包被安装在设备上。你可以做到这一点是这样的:

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
}

方法 getFilePathFromVideURI 是基于对这个问题的答案:的获取的URI文件名和路径从mediastore

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 乌里指向是这样的:内容://媒体/外部/视频/媒体/ 43 。您可以通过发出ACTION_PICK意图合一:

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

onActivityResult 得到URI像这样:

....
case PICK_VIDEO_REQUEST:
    Uri videoUri = data.getData();
     ...

该解决方案适用于我的Galaxy Nexus的采用Android 4.3果冻豆。

This solution works on my Galaxy Nexus with Android 4.3 Jelly Bean.

我不知道这是否适用于所有的Andr​​oid设备。 更可靠的解决方案可能是派生的库2应用程序,并把TrimVideo活动连同其依赖关系,可与您的应用程序交付的图书馆。 希望这有助于反正。

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.

这篇关于启动修剪视频活动,意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆