0

is possible to load thumbnails with Universal image Loader for android?. i got Thumbnail of image and video file in Sdcard then i don't know how to display these thumbnails with using of this library in gridview so please tell me anyone know how to do?

i got thumbnail from this code:

protected Integer doInBackground(Integer... params) {
        // TODO Auto-generated method stub

        final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };           // Images getting
        final String orderBy = MediaStore.Images.Media.DATE_TAKEN;

        imagecursor =  mContext.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                null, orderBy);
        int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
        this.count = imagecursor.getCount();
        /*this.count = params[0];

        if(count == 0)
            this.count = imagecursor.getCount();
        else if(count >= 12)

        */
        bitList = new ArrayList<Bitmap>();
        arrPathList = new ArrayList<String>();
        selectedPath = new ArrayList<String>();

        for (int i = 0; i < this.count; i++) {
            imagecursor.moveToPosition(i);
            int id = imagecursor.getInt(image_column_index);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);

            bitList.add( MediaStore.Images.Thumbnails.getThumbnail(
                    mContext.getContentResolver(), id,
                    MediaStore.Images.Thumbnails.MICRO_KIND, null));

            arrPathList.add(imagecursor.getString(dataColumnIndex));
        }

        this.durationcount = new ArrayList<String>();                                                  // Video Getting
        final String[] parameters = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, MediaStore.Video.Media.DURATION , MediaStore.Video.Media.MIME_TYPE}; // Videos getting
        final String orderBy_v = MediaStore.Video.Media._ID;

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

        int video_column_index = videocursor.getColumnIndex(MediaStore.Video.Media._ID);
        int video_column_duration = videocursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.DURATION);           // for duration of the video
        totalCount = imagecursor.getCount() + videocursor.getCount();                         /// Checking
        durationcount_a = new String[imagecursor.getCount() + videocursor.getCount()];

        for(int i = 0; i < videocursor.getCount(); i ++){
            videocursor.moveToPosition(ii);
            int id_v = videocursor.getInt(video_column_index);
            int datacolumn_v = videocursor.getColumnIndex(MediaStore.Video.Media.DATA);
            long duration = videocursor.getInt(video_column_duration);             // getting duration of the every videos

            String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(duration), 
                    TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)),
                    TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));

            durationcount.add(hms);
            durationcount_a[(imagecursor.getCount()) + ii] = hms;           
            bitList.add(MediaStore.Video.Thumbnails.getThumbnail(mContext.getContentResolver(), id_v,
                    MediaStore.Video.Thumbnails.MICRO_KIND, null));
            arrPathList.add(videocursor.getString(datacolumn_v));
        }
        thumbnailsselection = new boolean[totalCount];
        return null;

    }

Thanks in advance.

siva
  • 375
  • 6
  • 24
  • Check: [Android – Select multiple photos from Gallery](http://www.technotalkative.com/android-select-multiple-photos-from-gallery/) – Paresh Mayani Dec 10 '13 at 05:34
  • Thanks for ur reply Actually already i have seen ur blog, really nice but where u have passed file path in imageLoader.displayImage() method and i tried also for image and video file but it will only display Thumbnails for image file only not for video file, i need to display thumbnails for both files how to do using this lib? – siva Dec 10 '13 at 08:09

1 Answers1

1

u have to get the path or uri of the thumbnail to load it using universal image loader.

see this to get the uri :-

Get thumbnail Uri/path of the image stored in sd card + android

i have also worked on same kind of project and hosted it over git-hub .. i have two versions of it one without ImageLoader and other with imageloader .. right now i have hosted only former one :-

here is the path https://github.com/r4jiv007/CustomFilePicker.git

here is the method i used :-

private String getImageThumbnail(int id) {
        final String thumb_DATA = MediaStore.Images.Thumbnails.DATA;
        final String thumb_IMAGE_ID = MediaStore.Images.Thumbnails.IMAGE_ID;
        Uri uri = thumbUri;
        String[] projection = {thumb_DATA, thumb_IMAGE_ID};
        String selection = thumb_IMAGE_ID + "=" + id + " AND " + MediaStore.Images.Thumbnails.KIND + "=" + MediaStore.Images.Thumbnails.MINI_KIND;
        Cursor thumbCursor = getContentResolver().query(uri, projection, selection, null, null);

        String thumbPath = null;
        Bitmap thumbBitmap = null;
        if (thumbCursor != null && thumbCursor.getCount() > 0) {
            thumbCursor.moveToFirst();
            int thCulumnIndex = thumbCursor.getColumnIndex(thumb_DATA);

            thumbPath = thumbCursor.getString(thCulumnIndex);
/*
            Toast.makeText(getApplicationContext(),
                    thumbPath,
                    Toast.LENGTH_LONG).show();*/

            //  thumbBitmap = BitmapFactory.decodeFile(thumbPath);

        }
        Log.i("ImageMiniKind", thumbPath + "");
        return thumbPath;
    }

and u have to use :-

  imageLoader.displayImage("file://" + fileX.getmThumbPath() + "", imageView, options);

for loading the image.. and also beware some times there is no thumbnail for images !!

for loading thumbnail of video files

private String getVideoThumbnail(int id) {
    final String thumb_DATA = MediaStore.Video.Thumbnails.DATA;
    final String thumb_VIDEO_ID = MediaStore.Video.Thumbnails.VIDEO_ID;
    Uri uri = MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI;
    String[] projection = {thumb_DATA, thumb_VIDEO_ID};
    String selection = thumb_VIDEO_ID + "=" + id + " AND " + MediaStore.Video.Thumbnails.KIND + "=" + MediaStore.Video.Thumbnails.MINI_KIND;
    Cursor thumbCursor = getContentResolver().query(uri, projection, selection, null, null);
    String thumbPath = null;
    //  Bitmap thumbBitmap = null;
    if (thumbCursor.moveToFirst()) {

        int thCulumnIndex = thumbCursor.getColumnIndex(thumb_DATA);

        thumbPath = thumbCursor.getString(thCulumnIndex);
    }
    return thumbPath;
}

now all you have to do is pass the path to imageloader library

Community
  • 1
  • 1
r4jiv007
  • 2,974
  • 3
  • 29
  • 36
  • Thank u for reply, already i had worked in ur method that means i just passed path of both image and video file but i got thumbnail for image file only so i got thumbnail for both files now i need to load these thumbnails using this lib, i want to know Whether it is possible or not, let me know how to implement it? – siva Dec 09 '13 at 10:23
  • no this is the first time am using this lib with project, i had worked for getting thumb for image and video files in sdcard which could be implemented in asyntask, but in which very slow to retrieve all the thumbnails if more than 100 files in mobile so that's why am using this lib for retrieving thumb as faster – siva Dec 09 '13 at 13:29
  • how much have u implemented now ? – r4jiv007 Dec 09 '13 at 15:12
  • i have completed almost but i don't know how to pass the thumb image instead of path in this method - imageLoader.displayImage("file://" + fileX.getmThumbPath() + "", imageView, options); or has any other method to create video thumbnails in using of this lib? – siva Dec 10 '13 at 04:58
  • already i done this, now able to pass video path using imageloader lib,i could not get thumbnail in grid view but i got thumbnail for image file easily why this happening and how to get thumbnails for video file using this lib? – siva Dec 10 '13 at 13:43
  • post your logcat value – r4jiv007 Dec 11 '13 at 07:31
  • i am not face any exception yet but i passed path for video file there is no thumbnails, which shows empty image, why video path does not support in this lib(Universal image loader)? – siva Dec 11 '13 at 07:51
  • it supports .. i am using the same ..u can check it on my repo .. i doubt if there is any video thumbnail at all 1! – r4jiv007 Dec 11 '13 at 10:58
  • i could not import your file into my workspace, so kindly give me any other demo for file picker for Thumbnails to image and video file, if demo will be like drop box's file picker to upload files , really helpful – siva Dec 11 '13 at 12:45
  • u can just download and create new project using the code of the repo. i have used android studio for it so the directory structure is bit different !! – r4jiv007 Dec 11 '13 at 17:35
  • finally i got solution, loaded the thumbnails by using lazy loading in grid view and not have used image loader lib.now thumbnails loading fast. thanks for ur support – siva Dec 18 '13 at 06:29
  • @siva same issue with me how to resolve the loading the thumbnail fast with lazyloading, It would be good to share the code – Sunil Kumar Jun 17 '14 at 09:20
  • @sunil first u have to get the files path of video and image by using cursor object and separate them by using of Mime type then get both (video and image) thumbnails of them by using cursor object, now u can store those thumbnails into arraylist of bitmap and load as first 15 bitmaps and again load 15 when reach the end of scrolling in gridview. – siva Jun 18 '14 at 10:03
  • Okay i got bitmap of thumbnail of video and stored in list, but how to load first 15 and next 15, plz help me – Sunil Kumar Jun 18 '14 at 10:09
  • sort them by time , if u mean that , then load the first 15 – r4jiv007 Jul 01 '14 at 15:25
  • u have to use asyntask for load first 15 images and load again if touch the end of scrolling on the screen that means use some static variable and execute the asyntask in scroll listener. – siva Jul 11 '14 at 07:18