2014-06-27 101 views
0

我得到的位圖,從MediaStore這樣如何顯示存儲在特定的文件夾在SD卡

public class VideoStoredInSDCard extends Activity 
    { 
private Cursor videoCursor; 
private int videoColumnIndex; 
ListView videolist; 
    int count; 
String thumbPath; 

    String[] thumbColumns = {   MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.VIDEO_ID }; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
initialization(); 
} 

private void initialization() 
{ 
System.gc(); 
    String[] videoProjection = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA, 
    MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE }; 
    videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,videoProjection,   null, null, null); 
    count = videoCursor.getCount(); 
videolist = (ListView) findViewById(R.id.PhoneVideoList); 

videolist.setAdapter(new VideoListAdapter(this.getApplicationContext())); 
videolist.setOnItemClickListener(videogridlistener); 
} 

    private OnItemClickListener videogridlistener = new OnItemClickListener() { 
public void onItemClick(AdapterView parent, View v, int position,long id) 
    { 
    System.gc(); 
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); 
videoCursor.moveToPosition(position); 
String filename = videoCursor.getString(videoColumnIndex); 
Log.i("FileName: ", filename); 
//Intent intent = new Intent(VideoActivity.this, ViewVideo.class); 
//intent.putExtra("videofilename", filename); 
//startActivity(intent); 
}}; 

public class VideoListAdapter extends BaseAdapter 
{ 
private Context vContext; 
int layoutResourceId; 

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

    public int getCount() 
{ 
return videoCursor.getCount(); 
} 

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

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

public View getView(int position, View convertView, ViewGroup parent) 
{ 
View listItemRow = null; 
listItemRow = LayoutInflater.from(vContext).inflate(R.layout.listitem, parent, false); 

    TextView txtTitle = (TextView)listItemRow.findViewById(R.id.txtTitle); 
    TextView txtSize = (TextView)listItemRow.findViewById(R.id.txtSize); 
    ImageView thumbImage = (ImageView)listItemRow.findViewById(R.id.imgIcon); 

videoColumnIndex =   videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME); 
videoCursor.moveToPosition(position); 
txtTitle.setText(videoCursor.getString(videoColumnIndex)); 

videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE); 
videoCursor.moveToPosition(position); 
txtSize.setText(" Size(KB):" + videoCursor.getString(videoColumnIndex)); 

    int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); 
    Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, 
    thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null); 

if (videoThumbnailCursor.moveToFirst()) 
{ 
thumbPath =  videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbna  ils.DATA)); 
Log.i("ThumbPath: ",thumbPath); 

} 
thumbImage.setImageURI(Uri.parse(thumbPath)); 

return listItemRow; 

} 

} 

    } 

如何從SD卡中的特定文件夾的縮略圖得到所有的視頻縮略圖。我使用本教程http://gypsynight.wordpress.com/2012/02/17/how-to-show-all-video-file-stored-in-your-sd-card-in-a-listview/

回答

0

它可以很容易這樣做的話:

int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); 

ContentResolver cr = getContentResolver(); 
BitmapFactory.Options options=new BitmapFactory.Options(); 
options.inSampleSize = 1; 
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(cr, videoId, MediaStore.Video.Thumbnails.MICRO_KIND, options); 
thumbImage.setImageBitmap(curThumb); 
相關問題