自定义图库的图片和视频在Android中选择多个项目 [英] Custom Gallery with Images and Videos in android to select multiple items

查看:338
本文介绍了自定义图库的图片和视频在Android中选择多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义库中的SD卡显示所有图像和视频(以及持续时间)。我使用下面的code建立一个自定义库

i want to create a custom gallery to display all images and videos(along with duration) in sdcard. i am using the following code to build a custom gallery

code:

final String[] columns = { MediaStore.Images.Media.DATA ,MediaStore.Images.Media._ID};
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
    Cursor imagecursor = getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
            null, orderBy + " DESC");

    this.imageUrls = new ArrayList<String>();


    for (int i = 0; i < imagecursor.getCount(); i++) {
        imagecursor.moveToPosition(i);
        int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
        imageUrls.add(imagecursor.getString(dataColumnIndex));

    }
  String[] parameters = { MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.DATE_TAKEN,MediaStore.Video.Thumbnails.DATA};



     Cursor   videocursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, null, null, null);

     for (int i = 0; i < videocursor.getCount(); i++) {
         videocursor.moveToPosition(i);
         imageUrls.add(videocursor.getString(videocursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA)));
            }
    options = new DisplayImageOptions.Builder()
        .showStubImage(R.drawable.stub_image)
        .showImageForEmptyUri(R.drawable.image_for_empty_url)
        .cacheInMemory()
        .cacheOnDisc()
        .build();

    imageAdapter = new ImageAdapter(this, imageUrls);

从上面的codeI时能够获得视频的路径,我怎样才能获得视频的缩略图以及视频的持续时间。并重新present它在画廊

from the above code i am able to get the path of the video, how can i get the video thumbnail along with video duration. and represent it in the gallery

如果在项目定制画廊,视频和图片,请张贴链接任何BUIT  其实我是想创建一个自定义的画廊选择多个图片和视频文件。我搜索了很多在谷歌我发现自定义图片库,但不与视频请帮我解决这个问题。

if there are any buit in projects for custom gallery with videos and images please post the links i actually want to create a custom gallery to select multiple image and video files. i searched a lot in google i am finding the custom image gallery but not with videos please help me in solving this problem.

推荐答案

您可以采取的想法从自定义的GridView有多个选项,选择选项。 有一个在Github的开源项目。

You can take idea from Custom GridView with multiple option selection option. There is an open source project in Github.

<一个href="https://github.com/paramvir-b/AndroidGridViewCompatLib">https://github.com/paramvir-b/AndroidGridViewCompatLib

在这个例子中,你需要修改

in this example you need to change

 imageView.setImageResource(mThumbIds[position]);

imageView.setImageURI(uri);// URI of Image from SD Card

 imageView.setImageBitmap(bitmap);

有关视频: -

Video Thumbnail is in the form of Bitmap so you can show in ImageView.
private Bitmap bmThumbnail;
private ImageView videoview = null;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(PATH_OF_THE_VIDEO,Thumbnails.MICRO_KIND);
videoview.setImageBitmap(bmThumbnail);

获取时间: -

for getting Duration:-

String[] proj = { MediaStore.Video.Media.DATA ,MediaStore.Video.Media.DURATION};
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
if (cursor == null)
    return null;
int column_index = cursor
        .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
int column_index_duration = cursor
        .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
cursor.moveToFirst();
long duration= cursor.getInt(column_index_duration);
String videoPath= cursor.getString(column_index);

这篇关于自定义图库的图片和视频在Android中选择多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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