soheila soheila - 1 year ago 108
Android Question

How to list all video files on device

I want to get all videos path in android (Internal and External storage both), I have tried use:

List<String> paths = new ArrayList<String>();
File directory = new File("/system" OR "/mnt/sdcard");
File[] files = directory.listFiles();
for (int i = 0; i < files.length; ++i) {
if(files[i].getAbsolutePath().contains(".mp4")) {

but I can not get all of video lists from my device.

Answer Source

You need to make your search recursive. Something like:

void findVideos(File dir, ArrayList<String> list){
    for (File file : dir.listFiles()) {
        if (file.isDirectory()) findVideos(file, list);
        else if(file.getAbsolutePath().contains(".mp4")) list.add(file.getAbsolutePath());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download