• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps If and How to get video thumbnails?

kivy

Newbie
Jul 13, 2010
17
0
Hi,
I am working on a video app. And I have created a GridView that shall
display any video stored on the sdcard. Currently it only displays the
name of the video file.

I wanted to ask if and how it would be possible instead of showing
only the name to also display thumbs (or a frame preview) of the
videos ?!?

I would be grateful for any help...thanks.


This is the code I have used so far:

Code:
package com.mobilevideoeditor.moved;

   import android.app.Activity;
   import android.content.Context;
   import android.database.Cursor;
   import android.os.Bundle;
   import android.provider.MediaStore;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.BaseAdapter;
   import android.widget.GridView;
   import android.widget.TextView;




   public class EditGalleryView extends Activity {
       private Cursor videocursor;
       private int video_column_index;
       int count;

       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.videogrid);



           init_phone_video_grid();




       }

           private void init_phone_video_grid() {
           System.gc();
           String[] proj = {
                   MediaStore.Video.Media._ID,
                   MediaStore.Video.Media.DISPLAY_NAME,
                   MediaStore.Video.Media.DATA
           };

           videocursor =
managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,
null, null);
           count = videocursor.getCount();
           GridView vGrid=(GridView) findViewById(R.id.vgrid);
           vGrid.setAdapter(new VideoAdapter(this));
           }


       public class VideoAdapter extends BaseAdapter {
           private Context vContext;

           public VideoAdapter(Context c) {
               vContext = c;
           }

           public int getCount() {
               //return mThumbIds.length;
              return count;
           }


           public Object getItem(int position) {
               //return null;
               return position;
           }

           public long getItemId(int position) {
               //return 0;
               return position;
           }

           // create a new ImageView for each item referenced by the
Adapter
           public View getView(int position, View convertView,
ViewGroup parent) {
             System.gc();
             TextView tv = new
TextView(vContext.getApplicationContext());
             String id = null;
             if (convertView == null) {
                   video_column_index =

videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
                   videocursor.moveToPosition(position);
                   id = videocursor.getString(video_column_index);

                   tv.setText(id);
             } else
                   tv = (TextView) convertView;
             return tv;
           }



       }
 
While searching for a solution, I found the following for a similar question:

If you are using API 2.0 or newer this will work.

Code:
int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);

But right now I have NO IDEA where I should/could use that in my code and how to call the int id... please help...
 
Upvote 0
While searching for a solution, I found the following for a similar question:



But right now I have NO IDEA where I should/could use that in my code and how to call the int id... please help...

Without seeing some of your code it is impossible to tell... That code sets up the thumbnail from a MediaStore linked to the video you want to display. Depending on your code, you might have a method to set everything up and then call that method when you want the thumbnail to be created.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones