How to list all videos from specific folder in android

how to get video folder in android programmatically
android list files in internal storage
how to get list of audio files in a specific folder in android
android get list of folders in directory
android how to get all folders with photos
get list of all files in directory android
android get download folder path
open specific folder in android programmatically

I am working on video recording application.I want to list the videos which I would be stored in particular folder.By the following code,I can able to fetch all videos from mobile.But i need to list the videos from particular folder.Can anyone guide me please.Thanks in Advance

public class VideoListActivity extends Activity {
    private Cursor videocursor;
    private int video_column_index;
    ListView videolist;
    int count;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_list);
        init_phone_video_grid();
    }

    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.listView1);
        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);
            Intent intent = new Intent(VideoListActivity.this, Viewvideo.class);
            intent.putExtra("videofilename", filename);

            startActivity(intent);
        }
    };

    public class VideoAdapter extends BaseAdapter {
        private Context vContext;

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

        public int getCount() {
            return count;
        }

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

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

        public View getView(int position, View convertView, ViewGroup parent) {
            System.gc();
            TextView tv = new TextView(vContext.getApplicationContext());
            String id = null;
            if (convertView == null) {
                video_column_index = videocursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
                videocursor.moveToPosition(position);
                id = videocursor.getString(video_column_index);
                video_column_index = videocursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
                videocursor.moveToPosition(position);
                id += " Size(KB):" + videocursor.getString(video_column_index);


                        ImageView iv = new ImageView(vContext);
                        ContentResolver crThumb = getContentResolver();
                        BitmapFactory.Options options=new BitmapFactory.Options();
                        options.inSampleSize = 1;
                        Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, position, MediaStore.Video.Thumbnails.MICRO_KIND, options);
                        iv.setImageBitmap(curThumb);

                tv.setText(id);

            } else
                tv = (TextView) convertView;
            return tv;
        }
    }
}

use this code :

package com.vt.soc;

    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.ImageView;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemClickListener;


    public class MainActivity extends Activity {
        //set constants for MediaStore to query, and show videos
        private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        private final static String _ID = MediaStore.Video.Media._ID;
        private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
        //flag for which one is used for images selection
        private GridView _gallery; 
        private Cursor _cursor;
        private int _columnIndex;
        private int[] _videosId;
        private Uri _contentUri;
        String filename;
        int flag = 0;



        protected Context _context;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            _context = getApplicationContext();
            setContentView(R.layout.activity_main);
            //set GridView for gallery
            _gallery = (GridView) findViewById(R.id.videoGrdVw);
            //set default as external/sdcard uri
            _contentUri = MEDIA_EXTERNAL_CONTENT_URI;

            initVideosId();

            //set gallery adapter
            setGalleryAdapter();


        }
        private void setGalleryAdapter() {
            _gallery.setAdapter(new VideoGalleryAdapter(_context));
            _gallery.setOnItemClickListener(_itemClickLis);
            flag = 1;       
        }
        private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener() 
        {
            @SuppressWarnings({ "deprecation", "unused", "rawtypes" })
            public void onItemClick(AdapterView parent, View v, int position, long id) 
            {
                // Now we want to actually get the data location of the file
                String [] proj={MEDIA_DATA};
                // We request our cursor again
                _cursor = managedQuery(_contentUri,
                        proj, // Which columns to return
                        MEDIA_DATA + " like ? ",       // WHERE clause; which rows to return (all rows)
                        new String[] {"%Movies%"},       // WHERE clause selection arguments (none)
                        null); // Order-by clause (ascending by name)
                // We want to get the column index for the data uri
                int count = _cursor.getCount();
                //
                _cursor.moveToFirst();
                //
                _columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
                // Lets move to the selected item in the cursor
                _cursor.moveToPosition(position);
                // And here we get the filename
                filename = _cursor.getString(_columnIndex);
                //*********** You can do anything when you know the file path :-)
                showToast(filename);

                Intent i = new Intent(MainActivity.this, Player.class); 
                i.putExtra("videoPath", filename);
                startActivity(i);


                //
            }
        };
        @SuppressWarnings("deprecation")
        private void initVideosId() {
            try
            {
                //Here we set up a string array of the thumbnail ID column we want to get back
                String [] proj={_ID};
                // Now we create the cursor pointing to the external thumbnail store
                _cursor = managedQuery(_contentUri,
                        proj, // Which columns to return
                        MEDIA_DATA + " like ? ",       // WHERE clause; which rows to return (all rows)
                        new String[] {"%Movies%"},       // WHERE clause selection arguments (none)
                        null); // Order-by clause (ascending by name)
                int count= _cursor.getCount();
                // We now get the column index of the thumbnail id
                _columnIndex = _cursor.getColumnIndex(_ID);
                //initialize 
                _videosId = new int[count];
                //move position to first element
                _cursor.moveToFirst();          
                for(int i=0;i<count;i++)
                {           
                    int id = _cursor.getInt(_columnIndex);
                    //
                    _videosId[i]= id;
                    //
                    _cursor.moveToNext();
                    //
                }
            }catch(Exception ex)
            {
                showToast(ex.getMessage().toString());          
            }

        }
        protected void showToast(String msg)
        {
            Toast.makeText(_context, msg, Toast.LENGTH_LONG).show();
        }

        //
        private class VideoGalleryAdapter extends BaseAdapter
        {
            public VideoGalleryAdapter(Context c) 
            {
                _context = c;
            }
            public int getCount() 
            {
                return _videosId.length;
            }
            public Object getItem(int position) 
            {
                return position;
            }
            public long getItemId(int position) 
            {
                return position;
            }
            public View getView(int position, View convertView, ViewGroup parent) 
            {
                ImageView imgVw= new ImageView(_context);;
                try
                {
                    if(convertView!=null)
                    {
                        imgVw= (ImageView) convertView;
                    }
                    imgVw.setImageBitmap(getImage(_videosId[position]));
                    imgVw.setLayoutParams(new GridView.LayoutParams(200, 200));
                    imgVw.setPadding(8, 8, 8, 8);
                }
                catch(Exception ex)
                {
                    System.out.println("MainActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage());
                }
                return imgVw;
            }

            // Create the thumbnail on the fly
            private Bitmap getImage(int id) {
                Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
                        getContentResolver(),
                        id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
                return thumb;
            }

        }


    }

and add permission to manifest file:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

How to get list of video files in a specific folder in android?, you can use this code for get videos from specific folder as: String selection=​MediaStore.Video.Media.DATA +" like?"; String[] selectionArgs=new  I create a method that upload and save the video in "/download" folder in external storage in the android phone, if i use MediaStore.Video.Media.EXTERNAL_CONTENT_URI all video files will be include


Try the following code:

public static ArrayList<File> getListFiles(File parentDir) {
    ArrayList<File> inFiles = new ArrayList<File>();
    File[] files;
    files = parentDir.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().endsWith(".mp4") ||
                    file.getName().endsWith(".gif")) {
                if (!inFiles.contains(file)) inFiles.add(file);

                if (!inFiles.contains(file)) inFiles.add(file);
            }
        }
    }
    return inFiles;
}

Use :

private static final String WHATSAPP_STATUSES_LOCATION =  
"/storage/emulated/0/yourfoldername";


getListFiles(new File(WHATSAPP_STATUSES_LOCATION));

Access media files from shared storage, files to the MediaStore.Video table. Downloaded files, which are stored in the Download/ directory. On devices that run In particular, if your app wants to access a file within the MediaStore.Downloads Video.Media.DISPLAY_NAME, This will list all the files in the pictures folder. Use the path to your folder to get the files in that folder Dont forget to use the following permission <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


A bit late but posting for future viewers

Uri uri= MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String condition=MediaStore.Video.Media.DATA +" like?";
String[] selectionArguments=new String[]{"%FolderPath%"};
String sortOrder = MediaStore.Video.Media.DATE_TAKEN + " DESC";
String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME,MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri,projection, condition, selectionArguments, sortOrder);


int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
int pathColumn=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

if(cursor!=null){
    ContentResolver resolver = getApplicationContext().getContentResolver();
    while(cursor3.moveToNext()){
        String filePath=cursor.getString(pathColumn);
        int id = cursor.getInt(idColumn );
        Bitmap thumbNail = bitmap=MediaStore.Video.Thumbnails.getThumbnail(resolver, imageID, 
                                  MediaStore.Video.Thumbnails.MICRO_KIND, null);
    }
}

Android, Android Fetch Audio/MP3 files from specific folder of device or fetch all files The code above will return a list of all MP3 files with the music's name, path, artist​,  The code above will return a list of all MP3 files with the music's name, path, artist, and album. For more details please refer to the Media.Store.Audio documentation. In order to read files of a specific folder, use the following query (you need to replace the folder name):


use this code`  
String path = Environment.getExternalStorageDirectory().toString()+"/Your Folder/";`
 File f = new File(path);
 File file[] = f.listFiles();
for (int i=0; i < file.length; i++)
        {
            Log.d("Files", "FileName:" + file[i].getName());
        }

above code give you all file from the folder ,after you can separate using it's extension

How to show files and folders in android app, I want to show all root directory path of my android device from external and internal memory.. and i want to search particular folder from that list  Play all videos in a single folder. Is it possible to get a player that will play all video files in one folder on an SD card in sequence. I have tried a few times on mx player and vlc but it only plays one file and then returns to the list of video files.


how to get list of all folders and file from internal and external , You can view photos and videos on your phone & SD cards in Gallery Go: Photos​: To view all your photos and videos in one place, tap Photos Photos . Folders:  Suppose if all the files used in our project is stored in particular folder, like whatsapp image folder, we might be needed to display all files as well in some screen. In this tutorial we will learn how to list all files inside a directory.


Manage your photos with Gallery Go - Android Help, Find & delete files on Android. On your phone, you can usually find your files in the Files app Files app . Learn how to get help for your specific device. For example, learn how to find videos downloaded in the Google Play Movies & TV app. a computer by USB cable, open the computer's "Downloads" folder to find the  The latest version of Android has improved its built-in file manager. Here's how to use Android 10's file manager.


Find & delete files on Android - Android Help, OneDrive for Android OneDrive for iOS OneDrive for Windows Devices. Make sure the folder contents appear in List view, not as thumbnails. holding one photo or video, then tapping the circle next to additional file names to check them. below code for getting a list of all folders and file. Hide Copy Code. searchTXT ( new File (Environment.getExternalStorageDirectory ().getPath ())); private void searchTXT (File dir) { File [] files = dir.listFiles (); for (File file : files) { if (file.isFile () && isTXT (file)) { allTXT.add (file); Log.i ( "TXT", file.getName ()); } else if (file.isDirectory ()) { searchTXT (file.getAbsoluteFile ()); } } private boolean isTXT (File file) { boolean is = false; if (file.getName ().