Need help - If and How to get and display video thumbnails??

All your problems with Audio, Video and Images.

Need help - If and How to get and display video thumbnails??

Postby kivy » Sat Jul 17, 2010 10:27 pm

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.

[UPDATE]: While searching for a solution I found this: MediaStore.Video.Thumbnails, the only problem I have right now is, I don't really know and understand how to integrate that into my code...

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


This is the code I have used so far:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.mobilevideoeditor.moved;
  2.  
  3.    import android.app.Activity;
  4.    import android.content.Context;
  5.    import android.database.Cursor;
  6.    import android.os.Bundle;
  7.    import android.provider.MediaStore;
  8.    import android.view.View;
  9.    import android.view.ViewGroup;
  10.    import android.widget.BaseAdapter;
  11.    import android.widget.GridView;
  12.    import android.widget.TextView;
  13.  
  14.  
  15.  
  16.  
  17.    public class EditGalleryView extends Activity {
  18.        private Cursor videocursor;
  19.        private int video_column_index;
  20.        int count;
  21.  
  22.        public void onCreate(Bundle savedInstanceState) {
  23.            super.onCreate(savedInstanceState);
  24.            setContentView(R.layout.videogrid);
  25.  
  26.  
  27.  
  28.            init_phone_video_grid();
  29.  
  30.  
  31.  
  32.  
  33.        }
  34.  
  35.            private void init_phone_video_grid() {
  36.            System.gc();
  37.            String[] proj = {
  38.                    MediaStore.Video.Media._ID,
  39.                    MediaStore.Video.Media.DISPLAY_NAME,
  40.                    MediaStore.Video.Media.DATA
  41.            };
  42.  
  43.            videocursor =
  44. managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,
  45. null, null);
  46.            count = videocursor.getCount();
  47.            GridView vGrid=(GridView) findViewById(R.id.vgrid);
  48.            vGrid.setAdapter(new VideoAdapter(this));
  49.            }
  50.  
  51.  
  52.        public class VideoAdapter extends BaseAdapter {
  53.            private Context vContext;
  54.  
  55.            public VideoAdapter(Context c) {
  56.                vContext = c;
  57.            }
  58.  
  59.            public int getCount() {
  60.                //return mThumbIds.length;
  61.               return count;
  62.            }
  63.  
  64.  
  65.            public Object getItem(int position) {
  66.                //return null;
  67.                return position;
  68.            }
  69.  
  70.            public long getItemId(int position) {
  71.                //return 0;
  72.                return position;
  73.            }
  74.  
  75.            // create a new ImageView for each item referenced by the
  76. Adapter
  77.            public View getView(int position, View convertView,
  78. ViewGroup parent) {
  79.              System.gc();
  80.              TextView tv = new
  81. TextView(vContext.getApplicationContext());
  82.              String id = null;
  83.              if (convertView == null) {
  84.                    video_column_index =
  85.  
  86. videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
  87.                    videocursor.moveToPosition(position);
  88.                    id = videocursor.getString(video_column_index);
  89.  
  90.                    tv.setText(id);
  91.              } else
  92.                    tv = (TextView) convertView;
  93.              return tv;
  94.            }
  95.  
  96.        }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
kivy
Freshman
Freshman
 
Posts: 8
Joined: Thu Jul 15, 2010 2:55 am

Top

Re: Need help - If and How to get and display video thumbnai

Postby AndNewbie » Sun Jul 18, 2010 5:48 pm

Hey kivy,

I just wanted to post something similar and then I stumbled over your post...so I am going to wait now and see what happens...hopefully someone will help us in our misery ;)

Cheers...
AndNewbie
Freshman
Freshman
 
Posts: 2
Joined: Thu Jul 15, 2010 4:56 pm

Re: Need help - If and How to get and display video thumbnai

Postby kivy » Mon Jul 19, 2010 11:59 am

While searching for a solution I found this post someone replied to a similar question:

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

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int id = **"The Video's ID"**
  2. ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
  3. ContentResolver crThumb = getContentResolver();
  4. BitmapFactory.Options options=new BitmapFactory.Options();
  5. options.inSampleSize = 1;
  6. Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
  7. iv.setImageBitmap(curThumb);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4




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...
kivy
Freshman
Freshman
 
Posts: 8
Joined: Thu Jul 15, 2010 2:55 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests