2016-08-06 3 views
0

bekommen ich alle Videos Informationen in Android bekommen wollen, habe ich versucht, den EinsatzWie alle Videos in android

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

Dies kann jedoch nur die Videos bekommen, die ich gefangen. Ich möchte alle Videos auf meinem Handy abrufen, nicht nur die Videos, die ich aufgenommen habe, sondern auch die Videos, die ich aus dem Internet heruntergeladen habe.

+0

http://stackoverflow.com/questions/10503840/how-to-get-all-videos-on-android-device – bond007

Antwort

0

versuchen diese

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

Hier FileUtils ist

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; 
} 
Verwandte Themen