Hi,
I have been trying to display thumbnails of videos that I have stored
on the SD card of the emulator.
On stackflow someone posted the following code to a similar question
of somebody else:
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);
And I also read about MediaStore.Video.Thumbnails on the android dev
site...but I have to say, that I don't fully understand it yet and I
just have no idea, if, how and where I could use that in my code. And
everything I tried didn't... I am really getting a bit desperate at
the moment. If someone could help me by explaining or showing me what
I should do, I would be really grateful.
This is the code I have so far...
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;
private static int displayNameIndex = -1;
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 count;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView,
ViewGroup
parent) {
TextView tv;
String id;
if (convertView == null) {
// Need to create a new view
tv = new TextView(vContext);
} else {
// Otherwise, we can recycle the one given to us
tv = (TextView) convertView;
}
// Cache column index (or just hardcode it)
if (displayNameIndex == -1) {
displayNameIndex =
videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
}
// Bind cursor data to UI
videocursor.moveToPosition(position);
id = videocursor.getString(displayNameIndex);
tv.setText(id);
// Bundle video URI into the view
String videoUri = videocursor.getString(2); // column
index of Media.DATA
tv.setTag(videoUri);
return tv;
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en