If and How to get video thumbnails?


Last Updated:

  1. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    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 (Text):
    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.  
    97.  
    98.        }
     

    Advertisement
  2. AndNewbie

    AndNewbie New Member

    Joined:
    Jul 18, 2010
    Messages:
    1
    Likes Received:
    0
    Hey kivy,

    I have a similar problem, thought I might find something here...then I stumbled over your post...so I am going to wait now before I post something...hopefully someone will help us in our misery

    Cheers...
     
  3. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    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...
     
  4. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    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.
     

Share This Page

Loading...