3

I need a video gallery on Android sorted by the newest. With the code below, the sorting is with oldest videos on top and newest videos on last. So I need to scroll the entire list before getting the new recorded videos.

Any ideas to solve this ?

 private void init_phone_video_grid() {

    System.gc();
    String[] proj = { 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,
            proj, null, null, null);
    count = videocursor.getCount();
    videolist = (ListView) findViewById(R.id.PhoneVideoList);
    videolist.setAdapter(new VideoAdapter(getApplicationContext()));
    videolist.setOnItemClickListener(videogridlistener);


}

private OnItemClickListener videogridlistener = new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position,
            long id) {
        System.gc();
        video_column_index = videocursor
                .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        videocursor.moveToPosition(position);
        String filename = videocursor.getString(video_column_index);



        String videoinfo[] = new String[2];

        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.Thumbnails.DATA));
            Log.d("ThumbPath: ",thumbPath);

        }

        videoinfo[0] = filename;
        videoinfo[1] = thumbPath;

        Intent intent = new Intent(StoredVideo.this, VideoCompress.class);
        intent.putExtra(EXTRA_MESSAGE, videoinfo);

        StoredVideo.this.startActivity(intent);


    }
};
andreasperelli
  • 1,034
  • 2
  • 11
  • 40

1 Answers1

14

Solved with:

     String orderBy = android.provider.MediaStore.Video.Media.DATE_TAKEN;
     videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            proj, null, null, orderBy + " DESC");
andreasperelli
  • 1,034
  • 2
  • 11
  • 40