siva
siva

Reputation: 375

load thumbnails with Universal Image Loader for Android?

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.

Upvotes: 0

Views: 4586

Answers (1)

r4jiv007
r4jiv007

Reputation: 3104

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

Upvotes: 1

Related Questions