0

I want to get all videos information in android, I have tried use

Cursor cursor = context.getContentResolver().query(  
                MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null,  
                null, null);  

However, this can only get the videos which I captured. I want to get all videos in my phone,not only the videos I captured ,but also the videos I download from the Internet.

gus_gao_CHINA
  • 89
  • 1
  • 1
  • 8

1 Answers1

0

try this

public void eachAllMedias(File f) {
    if (f != null && f.exists() && f.isDirectory()) {
        File[] files = f.listFiles();
        if (files != null) {
            for (File file : f.listFiles()) {
                if (file.isDirectory()) {
                    eachAllMedias(file);

                } else if (file.exists() && file.canRead()
                        && FileUtils.isVideoOrAudio(file)) {
                    list.add(file.getName());
                }
            }
        }
    }
}

Here is FileUtils

public class FileUtils {

/**
 * @throws Exception */
public static boolean isVideoOrAudio(File f)  {
    final String ext = getFileExtension(f);
    ArrayList<String> list = new ArrayList<String>();
    list.add("avi");
    list.add("rmvb");
    list.add("wmv");
    list.add("mkv");
    list.add("mp4");

    return list.contains(ext);

}

/**  
 * @throws Exception */
public static String getFileExtension(File f) {
    if (f != null) {
        String filename = f.getName();
        int i = filename.lastIndexOf('.');
        if (i > 0 && i < filename.length() - 1) {
            return filename.substring(i + 1).toLowerCase();
        }

    }
    return null;
}
gus_gao_CHINA
  • 89
  • 1
  • 1
  • 8