I'm new to android development, and I'm listing all videos from storage(my mobile) and want to create thumbnail display in custom ListView
.
My problem is when creating the thumbnail it's taking time, how to solve this ? please help me out.
below code is to create the thumbnail
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.video_list);
ListView videolist=(ListView)findViewById(R.id.video_list);
ArrayList<String> videoName = new ArrayList<>();
final ArrayList<String> videoPath = new ArrayList<>();
ArrayList<Bitmap> videoThumbnail = new ArrayList<>();
String selection =MediaStore.Video.Media._ID;
String[] columns = { MediaStore.Video.Media.DATA,MediaStore.Video.Media.DISPLAY_NAME};
Cursor cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
columns, selection, null, null);
while (cursor.moveToNext()){
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(String.valueOf(Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)))),
MediaStore.Video.Thumbnails.MICRO_KIND);
videoName.add(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)));
videoPath.add(String.valueOf(Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)))));
videoThumbnail.add(bmThumbnail);
}
cursor.close();
Toast.makeText(getApplicationContext(), ""+videoThumbnail.size(), Toast.LENGTH_LONG).show();
VideoAdapter videoAdapter = new VideoAdapter(this, videoName,videoThumbnail);
videolist.setAdapter(videoAdapter);