从Mediastore排序Android列表中的顺序

时间:2014-07-21 13:34:02

标签: android sorting video mediastore

我需要Android上的视频库按最新排序。使用下面的代码,排序包含最新的视频和最新的视频。所以我需要在获取新录制的视频之前滚动整个列表。

有什么想法可以解决这个问题吗?

 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);


    }
};

1 个答案:

答案 0 :(得分:8)

解决:

     String orderBy = android.provider.MediaStore.Video.Media.DATE_TAKEN;
     videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            proj, null, null, orderBy + " DESC");