lolliloop
lolliloop

Reputation: 399

Display all the video from a specific folder in SD card in android

aI am having a problem in displaying all the videos inside a folder in SD card. Currently, I am able to display all the videos that can be found in SD card, but what I am trying to do is to display all the video inside the "PartyVideo" folder inside the SD card. Can you help me?Below is my code that display all the video in SD card.

final String[] columns = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID };
    final String orderBy   = MediaStore.Video.Media.DATE_TAKEN;
    Cursor imagecursor     = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null,null, orderBy + " DESC");
    int image_column_index = imagecursor.getColumnIndex(MediaStore.Video.Media._ID);
    this.count             = imagecursor.getCount();
    this.thumbnails        = new Bitmap[this.count];
    this.arrPath           = new String[this.count];
    this.thumbnailsselection = new boolean[this.count];
    for (int i = 0; i < this.count; i++) 
    {
        imagecursor.moveToPosition(i);
        int id = imagecursor.getInt(image_column_index);
        int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Video.Media.DATA);
        thumbnails[i] = MediaStore.Video.Thumbnails.getThumbnail(
                getApplicationContext().getContentResolver(), id,
                MediaStore.Video.Thumbnails.MICRO_KIND, null);
        arrPath[i]= imagecursor.getString(dataColumnIndex);
    }
    GridView imagegrid = (GridView) findViewById(R.id.grid_GalleryImage);
    imageAdapter = new ImageAdapter();
    imagegrid.setAdapter(imageAdapter);

I tried many different code, and end up with this one. The code below gets all that video in the folder I want but I don't know how can I display it.

String[] fileList = null;
     File videoFiles = new File(Environment.getExternalStorageDirectory()+"/PartyVideo");

        if(videoFiles.isDirectory())
        {
            fileList=videoFiles.list();
        }

       for(int i=0;i<fileList.length;i++)
       {
           Log.e("Video:"+i+" File name",fileList[i]);
       }

Upvotes: 0

Views: 4226

Answers (3)

Mohamad Shaker
Mohamad Shaker

Reputation: 1486

try this

Cursor videocursor = getActivity().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                        columns,
                        MediaStore.Video.Media.DATA + " like ? ",
                        new String[]{"%/" + Your folder name + "/%"},
                        null);

Upvotes: 1

user2298296
user2298296

Reputation: 91

Just try this hope it will work for you. http://android-er.blogspot.in/2011/05/display-video-thumbnail-in-listview.html

Upvotes: 1

Ali Imran
Ali Imran

Reputation: 9217

Use this File Browser library to browse through files and put the filter of video type in the following code

Intent intent = new Intent(getBaseContext(), FileDialog.class);
intent.putExtra(FileDialog.START_PATH, "/sdcard");

 //can user select directories or not
intent.putExtra(FileDialog.CAN_SELECT_DIR, true);

 //alternatively you can set file filter
intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { "avi" });

startActivityForResult(intent, REQUEST_SAVE);

Upvotes: 2

Related Questions