I need to display thumbnail of each video in list view using Picasso library for running faster so i need get thumbnail path to use.
This is my code to get thumbnail path(I found it on Google and i change something to adapt for my application):
String getThumbnailPathForLocalFile(Uri uri)
     {
         Cursor thumbCursor = null;
         try
         {
             thumbCursor = c.getContentResolver().
                     query(uri
                     , null
                     , null , null, null);
             if(thumbCursor.moveToFirst())
             {
                 // the path is stored in the DATA column
                 int dataIndex = thumbCursor.getColumnIndexOrThrow( MediaStore.MediaColumns.DATA );
                 String thumbnailPath = thumbCursor.getString(dataIndex);
                 return thumbnailPath;
             }
         }
         finally
         {
             if(thumbCursor != null)
             {
                 thumbCursor.close();
             }
         }
         return null;
     }
My getView function:
@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) c
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.listview_item, null);
        }
        /* create a new view of my layout and inflate it in the row */
        // convertView = ( RelativeLayout ) inflater.inflate( resource, null );
        final Item item = items.get(position);
        if (item != null) {
            TextView t1 = (TextView) v.findViewById(R.id.txt_fileName);
            imageCity = (ImageView) v.findViewById(R.id.img_icon);
            switch (item.getType()) {
            case "video":
                String uri2 = item.getPath();
                Uri videoUri = MediaStore.Video.Thumbnails
                        .getContentUri(uri2);
                String VideoThumbnailPath =getThumbnailPathForLocalFile(videoUri);
                Picasso.with(c).load(new File(VideoThumbnailPath))
                        .resize(64, 64).into(imageCity);
                break;
            case "image":
                String uri4 = item.getPath();
                Picasso.with(c).load(new File(uri4)).resize(64, 64).into(imageCity);
                break;
            default:
                break;
            }
            if (t1 != null)
                t1.setText(item.getName());
        }
        return v;
    }
I check logcat and debug so i found that thumbCursor is null:
12-10 17:52:38.400: E/AndroidRuntime(8659): java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.database.Cursor.moveToFirst()' on a null object reference
12-10 17:52:38.400: E/AndroidRuntime(8659):     at com.example.knock.FileArrayAdapter.getThumbnailPathForLocalFile(FileArrayAdapter.java:105)
12-10 17:52:38.400: E/AndroidRuntime(8659):     at com.example.knock.FileArrayAdapter.getView(FileArrayAdapter.java:73)
Anybody can help me ? Thanks you very much
 
                        
Your Uri is not correct.
getContentUri(String volumeName)expects the magic word"external"instead of a path. And you may not have a thumbnail yet.You can load thumbnails with this piece of code
What it does is:
Video.MediagetThumbnailwhich blocks (in your case the ui thread..) until the thumbnail was made & decoded.Big downside is that you can't use a path for Picasso here. (Custom loading works, https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/MediaStoreRequestHandler.java seems to be an implementation, some description about it here: http://blog.jpardogo.com/requesthandler-api-for-picasso-library/ )
You can get thumbnail paths, but if you have a look at the content of the thumbnails table, e.g. via this snippet of code
You'll see that not every video has a thumbnail.
But those that have can be found via
(still the same
PROJECTION&SELECTIONconstants from above)