Android 检索本地所有的视频

  1. package com.example.yanshishow;  
  2.   
  3. //电影视频的model类  
  4. public class MMM {  
  5.   
  6.       
  7.     String name;  
  8.     long size;  
  9.     String url;  
  10.     long duration;  
  11.     public String getName1() {  
  12.         return name;  
  13.     }  
  14.     public void setName1(String name) {  
  15.         this.name = name;  
  16.     }  
  17.     public long getSize1() {  
  18.         return size;  
  19.     }  
  20.     public void setSize1(long size) {  
  21.         this.size = size;  
  22.     }  
  23.     public String getUrl1() {  
  24.         return url;  
  25.     }  
  26.     public void setUrl1(String url) {  
  27.         this.url = url;  
  28.     }  
  29.     public long getDuration1() {  
  30.         return duration;  
  31.     }  
  32.     public void setDuration1(long duration) {  
  33.         this.duration = duration;  
  34.     }  
  35.       
  36.       
  37.   
  38.   
  39.       
  40.   
  41.       
  42.       
  43.   
  44. }  
然后就直接一个方法就可以了  方法如下


[html]  view plain  copy
  1. public List<MMM> getList() {  
  2.     List<MMM> list = null;  
  3.     if (this != null) {  
  4.         Cursor cursor = this.getContentResolver().query(  
  5.                 MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null,  
  6.                 null, null);  
  7.         if (cursor != null) {  
  8.             list = new ArrayList<MMM>();  
  9.             while (cursor.moveToNext()) {  
  10.                 int id = cursor.getInt(cursor  
  11.                         .getColumnIndexOrThrow(MediaStore.Video.Media._ID));  
  12.                 String title = cursor  
  13.                         .getString(cursor  
  14.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));  
  15.                 String album = cursor  
  16.                         .getString(cursor  
  17.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM));  
  18.                 String artist = cursor  
  19.                         .getString(cursor  
  20.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));  
  21.                 String displayName = cursor  
  22.                         .getString(cursor  
  23.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME));  
  24.                 String mimeType = cursor  
  25.                         .getString(cursor  
  26.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));  
  27.                 String path = cursor  
  28.                         .getString(cursor  
  29.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));  
  30.                 long duration = cursor  
  31.                         .getInt(cursor  
  32.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));  
  33.                 long size = cursor  
  34.                         .getLong(cursor  
  35.                                 .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));  
  36.                 MMM video = new MMM();  
  37.                 video.setName1(title);  
  38.                  video.setSize1(size);  
  39.                  video.setUrl1(path);  
  40.                  video.setDuration1(duration);  
  41.                 list.add(video);  
  42.             }  
  43.             cursor.close();  
  44.         }  
  45.     }  
  46.     return list;  
  47. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值